Results 1 to 3 of 3

Thread: [RESOLVED] DGV+ binding source( table filled with OleDBDataAdapter) - call adapter Command

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2013
    Posts
    134

    Resolved [RESOLVED] DGV+ binding source( table filled with OleDBDataAdapter) - call adapter Command

    Hi!

    Today I learned about the possibility to set the UpdateCommand, InsertCommand and DeleteCommand on the OleDbDataAdapter which I use to fill the datatable which through a binding source displays data in my DataGridView.
    Now I wonder, and cannot find an answer. Do I have to call those methods manually, or are they bound to some internal event handlers?

    Kind regards,
    Andy

    Before you ask for any code, here are the main parts:
    Code:
     myOleDBCommand.Connection = newConn
    myOleDBCommand.CommandText = sSQL 'SELECT statment string
    Dim dataAdapter As New OleDbDataAdapter(myOleDBCommand)
    Dim myTab As New DataTable()
    Dim insertCommand As OleDbCommand
    insertCommand = New OleDbCommand("INSERT ...")
    dataAdapter.InsertCommand = insertCommand
    dataAdapter.Fill(myTab)
    myGrid2BindingSource.DataSource = myTab
    myGrid2.DataSource = myGrid2BindingSource
    Last edited by AndyLD; May 14th, 2013 at 04:40 AM.

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

    Re: DGV+ binding source( table filled with OleDBDataAdapter) - call adapter Command

    Neither. When you call Fill on the adapter it executes the SelectCommand to retrieve data from the database into the DataTable. To save changes you call Update and it executes the InsertCommand, UpdateCommand and DeletedCommand as required to save rows that have been Added, Modified and Deleted respectively. You might follow the CodeBank link in my signature and check out my thread on Retrieving & Saving Data for an example.
    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
    Addicted Member
    Join Date
    Apr 2013
    Posts
    134

    Re: DGV+ binding source( table filled with OleDBDataAdapter) - call adapter Command

    Dear Jmcilhinney,

    thank you very much. Now it's clear. So I have to select the right event when to call the OleDbDataAdaper.Update() method.

    P.S. I opened your codebank thread and searched for "Retrieving & Saving Data", why doesn't this search match also "Retrieving and Saving Data" string ?
    Last edited by AndyLD; May 14th, 2013 at 05:53 AM.

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