Dapper 批量操作sql

    static void Main(string[] args)
        {
        private static readonly string sqlconnection ="";
//遍历循环client表 IList<Clients> StuList; using (var connection = new System.Data.SqlClient.SqlConnection(sqlconnection)) { connection.Open(); StuList = connection.Query<Clients>("select Prefix from Clients").ToList(); connection.Close(); } var conn = new System.Data.SqlClient.SqlConnection(sqlconnection); conn.Open(); try { int i = 1; foreach (Clients item in StuList) { var file = Environment.CurrentDirectory + "\\sql.txt"; var sql = System.IO.File.ReadAllText(file); sql = sql.Replace("{t}", item.Prefix); int result = conn.Execute(sql); Console.WriteLine("建立表--"+i+"----"+ item.Prefix+"_QueryLog"); i = i + 1; } } catch (Exception ex) { Console.WriteLine(ex.Message); } conn.Close(); Console.ReadLine(); }

 

posted @ 2017-06-20 18:07  幸福安康  阅读(1943)  评论(0编辑  收藏  举报