object reference not set to an instance of an object -
02-23-2005
, 04:00 PM
I get "object reference not set to an instance of an object " when running
the code below. Just tying to learn; took the code from a book. Tested the
connection string, and that's OK.
Private Sub Buttonj1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim con As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=F:\old
d\splash\SPLASH.MDB;Persist Security Info=False "
Dim sSQL As String
sSQL = "select * from company"
Dim objConn As New OleDb.OleDbConnection(con)
Dim da As New OleDb.OleDbDataAdapter(sSQL, con)
Dim ds As New DataSet("test")
Dim dv As DataView
Try
objConn.Open()
Catch myexception As System.Exception
Windows.Forms.MessageBox.Show(myexception.Message)
End Try
If objConn.State = ConnectionState.Open Then
Try
da.Fill(ds, "test")
objConn.Close()
Dim ot As DataTable
ot = ds.Tables("company")
dv = ot.DefaultView
TextBox1.DataBindings.Add("text", dv, "company")
Catch myexception As System.Exception
Windows.Forms.MessageBox.Show(myexception.Message)
End Try
End If
End Sub
End Class |