Results 1 to 3 of 3

Thread: [RESOLVED] Update to an Access DB

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    62

    Resolved [RESOLVED] Update to an Access DB

    I'm using OleDbDataAdapter1, OleDbConnection1, DataSet11.

    So why doesn't this code work:


    Code:
     Public Function CreateCmdsAndUpdate(ByVal DataSet11 As DataSet, ByVal myConnection As String, ByVal mySelectQuery As String, ByVal Bathroom As String) As DataSet
            Dim myConn As New OleDbConnection1(myConnection)
            Dim myDataAdapter As New OleDbDataAdapter()
            myDataAdapter.SelectCommand = New OleDbCommand(mySelectQuery, myConn)
            Dim custCB As OleDbCommandBuilder = New OleDbCommandBuilder(myDataAdapter)
    
            myConn.Open()
    
            Dim DataSet1 As DataSet = New DataSet()
            myDataAdapter.Fill(DataSet11)
    
            myDataAdapter.Update(DataSet11, Bathroom)
    
            myConn.Close()
    
            Return DataSet11
        End Function
    Thank you,
    Pierre

  2. #2
    Hyperactive Member ProphetBeal's Avatar
    Join Date
    Aug 2006
    Location
    New York
    Posts
    424

    Re: Update to an Access DB

    I made a few change to your code. If it doesn't help, are you getting a specific error with that code? How do you know it's not working?

    VB Code:
    1. Public Function CreateCmdsAndUpdate(ByVal DataSet11 As DataSet, ByVal myConnection As String, ByVal mySelectQuery As String, ByVal Bathroom As String) As DataSet
    2.         Dim myConn As New OleDbConnection(myConnection)
    3.         Dim myDataAdapter As New OleDbDataAdapter(mySelectQuery, myConn)
    4.         'myDataAdapter.SelectCommand = New OleDbCommand(mySelectQuery, myConn)
    5.         'Dim custCB As OleDbCommandBuilder = New OleDbCommandBuilder(myDataAdapter)
    6.  
    7.         myConn.Open()
    8.  
    9.         Dim DataSet1 As DataSet = New DataSet
    10.         myDataAdapter.Fill(DataSet11, Bathroom)
    11.  
    12.         'myDataAdapter.Update(DataSet11, Bathroom)
    13.  
    14.         myConn.Close()
    15.  
    16.         Return DataSet11
    17.     End Function

    Helpful Links:
    VB 6 - How to get the "Key" Value in a collection
    VB.NET - File Search Utility || VB.NET - How to compare 2 directories || VB.NET - How to trust a network share
    VB.NET - Create Excel Spreadsheet From Array || VB.NET - Example Code & Hints you may not know
    VB.NET - Save JPEG with a certain quality (image compression) || VB.NET - DragDrop Files, Emails, and Email Attachments

    Please post some of the code you need help with (it makes it easier to help you)
    If your problem has been solved then please mark the thread [RESOLVED].
    Don't forget to Rate this post

    "Pinky, you give a whole new meaning to the phrase, 'counter-intelligence'."-The Brain-

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

    Re: Update to an Access DB

    I'm afraid that your code doesn't make a lot of sense. Your method is named "CreateCmdsAndUpdate", which implies that you want to save the changes from an existing DataTable. Then you proceed to create a DataSet that you never use and retrieve data from the database. Finally you return the very same DataSet that you passed in.

    Please explain what the purpose of the method is. We can't tell you exactly what's wrong if we don't know what right is. Please take a little more time when posting and provide all the relevant information.
    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

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