使用OleDb连接数据库,怎么完成一个事务? 首先是源数据是否支持事务,如果不支持可以使用MTS,启动事务在Connection中有方法可以取得事务管理器 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 有没有人能告诉我OleDb是否支持事务,要怎样才能完成一个事务。 BeginTransaction,和COMMIT,ROLLBACK该怎么写呢,没有发现这些方法啊。 SqlConnection sqlConnection = new SqlConnection("workstation id=WEIXIAOPING;packet size=4096;user id=sa;initial catalog=Northwind;persist security info=False"); sqlConnection.Open(); SqlTransaction myTrans = sqlConnection.BeginTransaction(); SqlCommand sqlInsertCommand = new SqlCommand(); sqlInsertCommand.Connection = sqlConnection sqlInsertCommand.Transaction=myTrans; try{ sqlInsertCommand.CommandText="insert into tbTree(Context,ParentID) values('北京',1)"; sqlInsertCommand.ExecuteNonQuery(); sqlInsertCommand.CommandText="insert into tbTree(Context,ParentID) values('上海',1)"; sqlInsertCommand.ExecuteNonQuery(); myTrans.Commit(); }catch(Exception ex) { myTrans.Rollback(); } finally { sqlConnection.Close(); }这是sqlConnection 的一个例子,换成OleDbConnection 可以使用 COM+ 中的事务,使用 System.EnterpriseServices.ContextUtil 类。 datagridview表头的问题 C# 怎样验验字符串流是否有效的XML文件流? C#windows服务捕获全局异常 怎么获得网卡号呀? CSDN的管理员:你说这样的问题你叫我怎样去结贴?? 急求开发摄像头应用方面的技术,!! 200分,大家帮帮忙,关于拼音索引,有思路者就有分 高手怎么不来呀?。。。 C#网络编程求助,急!!! 这段C#程序运行时老产生Exception!Why? .net部署的问题,高手请进来看,请不要帖自带的Notepad演练 用客户端javascript脚本,如何将字符串拆分??
sqlConnection.Open();
SqlTransaction myTrans = sqlConnection.BeginTransaction();
SqlCommand sqlInsertCommand = new SqlCommand();
sqlInsertCommand.Connection = sqlConnection
sqlInsertCommand.Transaction=myTrans;
try{
sqlInsertCommand.CommandText="insert into tbTree(Context,ParentID) values('北京',1)";
sqlInsertCommand.ExecuteNonQuery();
sqlInsertCommand.CommandText="insert into tbTree(Context,ParentID) values('上海',1)";
sqlInsertCommand.ExecuteNonQuery();
myTrans.Commit();
}catch(Exception ex)
{
myTrans.Rollback();
}
finally
{
sqlConnection.Close();
}
这是sqlConnection 的一个例子,换成OleDbConnection