SqlTransaction 类
来源:互联网 发布:seo工程师培训 编辑:程序博客网 时间:2024/05/29 07:38
SqlTransaction 类
应用程序通过在 SqlConnection 对象上调用 BeginTransaction 来创建 SqlTransaction 对象。对 SqlTransaction 对象执行与该事务关联的所有后面的操作(例如提交或中止该事务)。
[C#]
public void RunSqlTransaction(string myConnString)
{
SqlConnection myConnection = new SqlConnection(myConnString);
myConnection.Open();
SqlCommand myCommand = myConnection.CreateCommand();
SqlTransaction myTrans;
// Start a local transaction
myTrans = myConnection.BeginTransaction();
// Must assign both transaction object and connection
// to Command object for a pending local transaction
myCommand.Connection = myConnection;
myCommand.Transaction = myTrans;
try
{
myCommand.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (100, 'Description')";
myCommand.ExecuteNonQuery();
myCommand.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (101, 'Description')";
myCommand.ExecuteNonQuery();
myTrans.Commit();
Console.WriteLine("Both records are written to database.");
}
catch(Exception e)
{
try
{
myTrans.Rollback();
}
catch (SqlException ex)
{
if (myTrans.Connection != null)
{
Console.WriteLine("An exception of type " + ex.GetType() +
" was encountered while attempting to roll back the transaction.");
}
}
Console.WriteLine("An exception of type " + e.GetType() +
" was encountered while inserting the data.");
Console.WriteLine("Neither record was written to database.");
}
finally
{
myConnection.Close();
}
}
- SqlTransaction 类
- SqlTransaction 类
- SqlTransaction 类
- SqlTransaction
- SqlTransaction
- ASP.NET Sqltransaction类的使用
- .NET中的处理 Transact-SQL 事务(C#)SqlTransaction 类
- 事务书写---SqlTransaction类 多条sql语句同事进行
- 关于sqltransaction
- 事务处理SqlTransaction
- SqlConnection,SqlTransaction,SqlDataReader解说
- SqlTransaction.Dispose,RollBack ?
- SqlTransaction的解析
- SqlConnection,SqlTransaction,SqlDataReader解说
- 关于SqlTransaction.Connection
- SqlTransaction.Commit 方法
- 解决SqlTransaction用尽的问题
- 解决SqlTransaction用尽的问题
- windows下配置PPPoE服务器
- 全面认识UML类图元素
- LINQ体验(17)——LINQ to SQL语句之动态查询
- Matlab与C语言程序的应用编程接口
- LINQ体验(18)——LINQ to SQL语句之视图和继承支持
- SqlTransaction 类
- LINQ可视化查询编辑器: VLinq
- 学习LINQ工具:LINQPad
- 求用java代码解析jar包
- 推荐一个IE下的优秀js调试工具(Companion.JS)
- Dojo1.1版Dialog、BorderContainer、ContentPane等集成测试例子
- the ID is OK
- ASP.NET下的EXCEL操作(总结篇)
- 事务管理