static async Task MySQLTransDemo() {
try { using(dbConnection) { dbConnection.Open();
//The object matched type such as class must have the column fields in table List objList = new List(); //assign values to objList; //to-do //objList=GetObjList(); using(IDbTransaction trans=dbConnection.BeginTransaction()) { //match columns and values respectively. string transSQL = "insert into table_Name(column1,column2) values(@column1,@column2)"; //In this example,this objList collection's item object must have column1 and column2 properties. var transNum = await dbConnection.ExecuteAsync(transSQL, objList, trans); trans.Commit(); if(transNum<0) { trans.Rollback(); } } } }
catch(Exception ex) { Console.WriteLine(ex.Message); } }
手机扫一扫
移动阅读更方便
你可能感兴趣的文章
4
5
6
7
8
9
10