connection属性尚未初始化

时间:2015-12-13 21:52:29

标签: sql vb.net oracle interface

我正在尝试为我的用户界面运行此代码,我将接口与我的数据库连接,我正确地完成了所有操作。但问题是这个错误一直显示,我不知道如何解决它。

错误显示“连接属性尚未初始化”

这是我的代码,

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

1 个答案:

答案 0 :(得分:0)

您需要初始化连接的连接字符串以设置连接。例如:

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