Results 1 to 7 of 7

Thread: [RESOLVED] MS Access/DataSet Issue

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    29

    Resolved [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:
    1. Private Sub btnMbrListImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMbrListImport.Click
    2.  
    3.         Dim DSMbrList As System.Data.DataSet
    4.         Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
    5.         Dim MyConnection As System.Data.OleDb.OleDbConnection
    6.  
    7.         MyConnection = New System.Data.OleDb.OleDbConnection( _
    8.             "provider = Microsoft.Jet.OLEDB.4.0; " & _
    9.             "data source = " & txtMbrList.Text & ";" & _
    10.             "userid=Admin;Password=")
    11.  
    12.         MyCommand = New System.Data.OleDb.OleDbDataAdapter( _
    13.         "select individual_id, member_nbr, participation_type" & _
    14.         "from db2inst1_membershipparticipant", MyConnection)
    15.  
    16.         DSMbrList = New System.Data.DataSet
    17.  
    18.         MyCommand.Fill(DSMbrList) 'This is the line that the error highlights
    19.         MyConnection.Close()
    20.  
    21.     End Sub

    I'm sure I'm just missing something easy.

    Thanks,
    Brad

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    29

    Re: MS Access/DataSet Issue

    I tried those changes and I'm still getting the same errors.

    See anything else?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Try
    2.     "Call fill here.
    3. Catch ex As Exception
    4.     MessageBox.Show(ex.ToString())
    5. End Try
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    29

    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.
    Attached Files Attached Files

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    VB Code:
    1. MyConnection.Open()
    you will get an exception thrown on that line instead. That would suggest that there is a problem with your connection string.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    29

    Re: MS Access/DataSet Issue

    Ok, didnt understant what you meant.

    Thanks again for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width