2015-12-13 243 views
0

我試圖爲我的用戶界面運行此代碼,我將界面與我的數據庫連接,並且我正確地執行了所有操作。但問題是這個錯誤不斷顯示,我不知道如何解決它。連接屬性尚未初始化

錯誤說「連接屬性尚未初始化」

這是我的代碼,

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 
+0

[SQL注入警報](http://msdn.microsoft.com/en-us/library/ms161953%28v=sql.105%29.aspx) - 您應該**不要* *連接你的SQL語句 - 使用**參數化查詢**而不是SQL注入 –

+0

我試圖添加OracleDataAdapter1.Connection = OracleConnection1,但它給了我那個連接不是OracleDataAdapter1的成員 – Moana

回答

0

您需要初始化的ConnectionString用於連接建立的連接。例如:

Dim OracleConnection1 As New OracleConnection("Data Source=ORCL;User Id=test;Password=test;"); 
OracleConnection1.Open(); 
+0

我試過了,它說這個類型的OracleConnection沒有定義,即使我在將數據庫連接到接口後添加了項目OracleConnection。 – Moana

+0

感謝它的工作,很抱歉回覆遲到 – Moana

相關問題