adalton11 Posted April 20, 2004 Posted April 20, 2004 I'm new at using vb.net to talk to databases and have been trying to follow examples that i have seen from other members. I'm trying to keep it simple by connecting to an access database but for some reason i always get this error when trying to run this code. An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim MyConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\ares\mis\data.mdb") MyConnection.Open() Dim MyCommand As New OleDbCommand("SELECT * FROM MyTable WHERE ID = 1", MyConnection) Dim MyReader As OleDbDataReader = MyCommand.ExecuteReader() While MyReader.Read Lastname.Text = MyReader("MyFName") FirstName.Text = MyReader("MyLName") Address.Text = MyReader("MyAddress") End While MyConnection.Close() MyReader.Close() MyCommand.Dispose() End Sub It errors out on this line Dim MyReader As OleDbDataReader = MyCommand.ExecuteReader() I've looked everywhere but haven't found a solution. Help please Quote
JumpsInLava Posted April 20, 2004 Posted April 20, 2004 Do this, and see what it tells you. Dim MyConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\ares\mis\data.mdb") MyConnection.Open() Dim MyCommand As New OleDbCommand("SELECT * FROM MyTable WHERE ID = 1", MyConnection) Try Dim MyReader As OleDbDataReader = MyCommand.ExecuteReader() Catch ex1 As System.Data.OleDb.OleDbException MessageBox.Show(ex1.Message) Catch ex2 As Exception MessageBox.Show(ex2.Message) End Try While MyReader.Read Lastname.Text = MyReader("MyFName") FirstName.Text = MyReader("MyLName") Address.Text = MyReader("MyAddress") End While MyConnection.Close() MyReader.Close() MyCommand.Dispose() [/Code] Quote
JumpsInLava Posted April 20, 2004 Posted April 20, 2004 Woops, shouldn't Dim in the Try block.... Dim MyConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\ares\mis\data.mdb") MyConnection.Open() Dim MyCommand As New OleDbCommand("SELECT * FROM MyTable WHERE ID = 1", MyConnection) Dim MyReader As OleDbDataReader Try MyReader = MyCommand.ExecuteReader() Catch ex1 As System.Data.OleDb.OleDbException MessageBox.Show(ex1.Message) Catch ex2 As Exception MessageBox.Show(ex2.Message) End Try While MyReader.Read Lastname.Text = MyReader("MyFName") FirstName.Text = MyReader("MyLName") Address.Text = MyReader("MyAddress") End While MyConnection.Close() MyReader.Close() MyCommand.Dispose() [/Code] Sorry.... Quote
adalton11 Posted April 20, 2004 Author Posted April 20, 2004 MSGBOX No Value Given for one or more required parameters. MDE Error An unhandled exception of type 'System.NullReferenceException' occurred in AccessDB.exe Additional information: Object reference not set to an instance of an object. This is a pain in the behind... Thanks for your help Quote
Moderators Robby Posted April 20, 2004 Moderators Posted April 20, 2004 Is there a column named ID and is it of numeric data type? Quote Visit...Bassic Software
adalton11 Posted April 20, 2004 Author Posted April 20, 2004 I'm a freaking retard, you guys both are guru's Thanks for your help Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.