[RESOLVED] MS Access/DataSet Issue
Im getting the following error when running the code below;
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll
VB Code:
Private Sub btnMbrListImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMbrListImport.Click
Dim DSMbrList As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Dim MyConnection As System.Data.OleDb.OleDbConnection
MyConnection = New System.Data.OleDb.OleDbConnection( _
"provider = Microsoft.Jet.OLEDB.4.0; " & _
"data source = " & txtMbrList.Text & ";" & _
"userid=Admin;Password=")
MyCommand = New System.Data.OleDb.OleDbDataAdapter( _
"select individual_id, member_nbr, participation_type" & _
"from db2inst1_membershipparticipant", MyConnection)
DSMbrList = New System.Data.DataSet
MyCommand.Fill(DSMbrList) 'This is the line that the error highlights
MyConnection.Close()
End Sub
I'm sure I'm just missing something easy.
Thanks,
Brad
Re: MS Access/DataSet Issue
If that is your actual code then you have no space character between the last field in the SELECT clause and the FROM keyword in your SQL statement. If that's just a typo then the problem is probably with your connection string. Try calling Open on the connection before calling Fill to check this. Also, unless you explicitly call Open before calling Fill you don't need to call Close. It won't hurt but if the connection is not already open then the call to Fill will open it, use it and then close it again.
Re: MS Access/DataSet Issue
I tried those changes and I'm still getting the same errors.
See anything else?
Re: MS Access/DataSet Issue
So you're saying that the connection gets opened successfully when you call Open but you get an exception thrown when you call Fill, correct? I'd suggest you put the line that throws the exception into a Try block to get as much info as possible:
VB Code:
Try
"Call fill here.
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
1 Attachment(s)
Re: MS Access/DataSet Issue
I used you code and it "worked". I have no idea what the error means though. This is my first real app and I've done very little debugging. Thanks for all of your help and being patient. I attached a SP of the error if your interested in looking at it.
Re: MS Access/DataSet Issue
The error message you provided shows that the call to Fill is implicitly trying to open the database connection and is failing. I previously suggested that you try to explicitly open the connection by calling Open on it. It would seem that you did not take that advice. I think you'll find that if you add this line before the call to Fill:you will get an exception thrown on that line instead. That would suggest that there is a problem with your connection string.
Re: MS Access/DataSet Issue
Ok, didnt understant what you meant.
Thanks again for your help.