1 public static DataTable ExeQuery(string connectionString, CommandType cmdType, string cmdText) 2 { 3 using (var conn = new SqlConnection(connectionString)) 4 { 5 var mydt = new DataTable(); 6 conn.Open(); 7 var cmd = conn.CreateCommand(); 8 cmd.CommandType = cmdType; 9 cmd.CommandText = cmdText; 10 var adp = new SqlDataAdapter(cmd); 11 adp.Fill(mydt); 12 return mydt; 13 } 14 } 15 16 public static async Task<DataTable> ExeQueryAsync(string connectionString, CommandType cmdType, string cmdText) 17 { 18 using (var conn = new SqlConnection(connectionString)) 19 { 20 var mydt = new DataTable(); 21 await conn.OpenAsync(); 22 var cmd = conn.CreateCommand(); 23 cmd.CommandType = cmdType; 24 cmd.CommandText = cmdText; 25 var adp = new SqlDataAdapter(cmd); 26 adp.Fill(mydt); 27 return mydt; 28 } 29 }
1 private string GetId(string LOCATION, string OPERATING_UNIT) 2 { 3 using (var db = new OMSData.ACC_MINIEHUBContext()) 4 { 5 string cmd = string.Format("select ww from wTES where LOCATION = '{0}' and OIT = '{1}'", LOCATION, OPERATING_UNIT); 6 var mytb = Asus.fn.fnSQL.ExeQuery(db.ACC_Context.ConnectionString, CommandType.Text, cmd); 7 var CUST_ACCOUNT_ID = mytb.Rows[0]["CUST_ID"].ToString(); 8 return CUST_ACCOUNT_ID; 9 } 10 }
1 cmd = string.Format("select DeptName from [V_ACC_USER] where EMPID = '{0}'", WorkId); 2 mytb = Asus.fn.fnSQL.ExeQuery(db.Context.ConnectionString, CommandType.Text, cmd); 3 string DeptName = "Err"; 4 if (mytb.Rows.Count > 0) 5 { 6 DeptName = mytb.Rows[0]["Name"].ToString(); 7 DeptName = DeptName.Substring(DeptName.LastIndexOf('-') + 1); 8 }