扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
1Public Sub RunOracleTransaction()Sub RunOracleTransaction(myConnString As String) 2 Dim myConnection As New OracleConnection(myConnString) 3 myConnection.Open() 4 5 Dim myCommand As OracleCommand = myConnection.CreateCommand() 6 Dim myTrans As OracleTransaction 7 8 ' Start a local transaction 9 myTrans = myConnection.BeginTransaction(IsolationLevel.ReadCommitted) 10 ' Assign transaction object for a pending local transaction 11 myCommand.Transaction = myTrans 12 13 Try 14 myCommand.CommandText = "INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')" 15 myCommand.ExecuteNonQuery() 16 myCommand.CommandText = "INSERT INTO Dept (DeptNo, Dname, Loc) values (60, 'ENGINEERING', 'KANSAS CITY')" 17 myCommand.ExecuteNonQuery() 18 myTrans.Commit() 19 Console.WriteLine("Both records are written to database.") 20 Catch e As Exception 21 myTrans.Rollback() 22 Console.WriteLine(e.ToString()) 23 Console.WriteLine("Neither record was written to database.") 24 Finally 25 myConnection.Close() 26 End Try 27End Sub 28 |
imgCommand.CommandText = sSQL imgCommand.ExecuteNonQuery()或其他操作 |
1 ''' <summary> 2 ''' 保存热点文本文件信息到数据库 3 ''' </summary> 4 Private Function SaveTextFile()Function SaveTextFile() As Boolean 5 Dim sSQl As String 6 sSQl = "select type_id from sys_file_type where file_extname='TXT'" 7 Try 8 imgCommand.CommandText = sSQl 9 Dim typeID As Int32 = Convert.ToInt32(imgCommand.ExecuteScalar()) '文件类型 10 '读取文本信息 11 Dim Textblob() As Byte = GetText() 12 13 sSQl = "insert into t_watch_textcontent(image_id,text_content,type_id) values(:imageid,:textcontent,:typeid)" 14 '增添SQL参数 15 Dim Param As OracleClient.OracleParameter 16 Param = New OracleClient.OracleParameter("imageid", sNewImageID) 17 imgCommand.Parameters.Add(Param) 18 Param = New OracleClient.OracleParameter("textcontent", Textblob) 19 imgCommand.Parameters.Add(Param) 20 Param = New OracleClient.OracleParameter("typeid", typeID) 21 imgCommand.Parameters.Add(Param) 22 23 '提交信息 24 imgCommand.CommandText = sSQl 25 If imgCommand.ExecuteNonQuery() > 0 Then 26 bResult = True 27 '关键是这里,需要你手动清除参数 28 imgCommand.Parameters.Clear() 29 End If 30 Catch ex As Exception 31 Me.ExceptionMessage = ex 32 bResult = False 33 End Try 34 35 Return bResult 36 End Function |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者