Core 项目下使用SQl语句

 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                 }

 

转载于:https://www.cnblogs.com/ZkbFighting/p/10948587.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值