SqlDatabase db = new SqlDatabase(@"server=.\sql2008;uid=sa;pwd=abc@123;database=EFDemo");

            DbConnection dbconn 
= db.CreateConnection();
            dbconn.Open();
            DbTransaction Idbtran 
= dbconn.BeginTransaction();
            
try
            {
                DbCommand sql 
= db.GetSqlStringCommand("Insert Into [Author](FirstName,LastName) Values('han1','wei1')");
                db.ExecuteNonQuery(sql,Idbtran);
                DbCommand sql1 
= db.GetSqlStringCommand("Update [Author] Set LastName = 'wei1xiu' where FirstName='han1'");
                db.ExecuteNonQuery(sql1,Idbtran);

                Idbtran.Commit();
            }
            
catch
            {
                Idbtran.Rollback();
            }
            
finally
            {
                dbconn.Close();
            }
            Console.WriteLine(
"OK");
            Console.ReadKey();

相关文章:

  • 2021-11-19
  • 2022-12-23
  • 2022-12-23
  • 2022-03-10
  • 2021-12-17
  • 2021-09-14
  • 2022-03-09
  • 2022-12-23
猜你喜欢
  • 2021-09-15
  • 2021-06-12
  • 2022-12-23
  • 2021-06-04
  • 2021-11-16
  • 2022-01-04
相关资源
相似解决方案