我試圖爲我的用戶界面運行此代碼,我將界面與我的數據庫連接,並且我正確地執行了所有操作。但問題是這個錯誤不斷顯示,我不知道如何解決它。連接屬性尚未初始化
錯誤說「連接屬性尚未初始化」
這是我的代碼,
Public Class ManageBus
Private Sub btnclear_Click(sender As Object, e As EventArgs) Handles btnclear.Click
txtbus.Text = Nothing
txtdriver = Nothing
End Sub
Private Sub btnexit_Click(sender As Object, e As EventArgs) Handles btnexit.Click
End
End Sub
Private Sub btnadd_Click(sender As Object, e As EventArgs) Handles btnadd.Click
Try
OracleConnection1.Open()
Dim command As String
command = "insert into BUS(Bus_ID, Driver_ID)" _
& " values('" & txtbus.Text & "', '" _
& txtdriver.Text & ")"
OracleDataAdapter1.InsertCommand.CommandText = command
lblsql.Text = command
OracleDataAdapter1.InsertCommand.ExecuteNonQuery()
MsgBox("Insert Successful", MsgBoxStyle.Information, "Insert Status")
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
OracleConnection1.Close()
End Try
End Sub
[SQL注入警報](http://msdn.microsoft.com/en-us/library/ms161953%28v=sql.105%29.aspx) - 您應該**不要* *連接你的SQL語句 - 使用**參數化查詢**而不是SQL注入 –
我試圖添加OracleDataAdapter1.Connection = OracleConnection1,但它給了我那個連接不是OracleDataAdapter1的成員 – Moana