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();
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();