我从来没有在VB.NET中对Oracle做过INSERT语句,所以我需要一些帮助。执行后没有任何反应,我的代码不起作用 - 没有错误,没有插入。有什么问题或者我在这里错过了什么? (Field1和Field2只是表字段,而不是主键。)
Imports System.Data
Imports Oracle.DataAccess.Client ' ODP.NET Oracle managed provider
Imports Oracle.DataAccess.Types
Public Class Save_Records
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Const conn As String = "Data Source=MyDB;User Id=Lucky;Password=MyPassword;"
Using cn As New OracleConnection(conn)
cn.Open()
Using cmd As New OracleCommand()
cmd.CommandText = "INSERT into MyTable (Field1,Field2) values('" & TxtField1.Text & "','" & TxtField2.Text & "')"
cmd.ExecuteNonQuery()
End Using
End Using
End Sub
End Class
答案 0 :(得分:2)
此方法是如何插入Oracle
的起点Private Function insertRow(connectionString As String) As Boolean
Using cn As OracleConnection = New OracleConnection(connectionString)
cn.Open()
Using cmd As OracleCommand = New OracleCommand()
Const sql As String = "Insert into test_table (val1, val2) values (:var1, :var2)"
cmd.Connection = cn
cmd.Parameters.Add(New OracleParameter("var1", TxtField1.Text))
cmd.Parameters.Add(New OracleParameter("var2", TxtField2.Text))
cmd.CommandText = sql
cmd.ExecuteNonQuery()
End Using
End Using
End Function