大家一起來談談
謝謝了~!
謝謝了~!
解决方案 »
- 帮我注释一下代码
- 用Visual Studio 内置的IIS调用DllImport很正常,请问IIS上如何调用DllImport
- 想做一个自定义WEB控件,才发现在windows 下面。 ,为什麽把WEB的东西放在WINDOWS项目下面呢???
- DataView中的 怎么表示编辑行? 在线等
- 样式设置的优先级问题
- 我有个关于水晶报表很简单的问题,但是真是用来救命的,有会制作水晶报表的大侠们,能不能帮帮我
- 这样的传递数据你能做到这到吗?
- 工作问题?
- c#调用sql insert语句 与触发器矛盾!!!
- table中的子控件怎么使用?
- 最后的50分求助!
- datagrid中点击checkbox就更新数据库中相对应的记录
所以我们的程序运行速度越快的时候程序的bug就越多,
这个能叫优雅不哦?
Dim myConnection As New SqlConnection(myConnString)
myConnection.Open()
Dim myCommand As SqlCommand = myConnection.CreateCommand()
Dim myTrans As SqlTransaction
' Start a local transaction
myTrans = myConnection.BeginTransaction(IsolationLevel.ReadCommitted, "SampleTransaction")
' 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 e As Exception
Try
myTrans.Rollback("SampleTransaction")
Catch ex As SqlException
If Not myTrans.Connection Is Nothing Then
Console.WriteLine("An exception of type " & ex.GetType().ToString() & _
" was encountered while attempting to roll back the transaction.")
End If
End Try
Console.WriteLine("An exception of type " & e.GetType().ToString() & _
"was encountered while inserting the data.")
Console.WriteLine("Neither record was written to database.")
Finally
myConnection.Close()
End Try
End Sub 'RunSqlTransaction