Results 1 to 3 of 3

Thread: [RESOLVED] Updating Access Database

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Posts
    256

    Resolved [RESOLVED] Updating Access Database

    Hi,

    I am binding the Datagrid by
    Code:
    DataGrid1.DataSource = ds
    now when i make any changes in the Datagrid how do i make the changes refect in the database..i..e how do i update the database

    I know that I can update the database with a single record by this
    Code:
                
    ds.Tables("Books").Rows(1).Item("Author") = txt1.Text
    da.Update(ds, "books")
    This is done only if i know that the record in row 1 and Column Authors has to be changed..
    where da is the data adapter and ds is the dataset
    Please advice...
    If an answer to your question has been helpful, then please, Rate it!

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

    Re: Updating Access Database

    You're trying to complicate things.

    1. Get your data:
    vb Code:
    1. da.Fill(ds, "books")
    2. Bind your data:
    vb Code:
    1. DataGrid1.DataMember = "books"
    2. DataGrid1.DataSource = ds
    3. The user makes as many changes as they like. They may add, edit or delete as many rows as they want.

    4. Save the changes:
    vb Code:
    1. da.Update(ds, "books")
    That's it. When the user edits the data in the grid those changes are automatically propagated to the bound DataTable. That's exactly what data-binding is for. Once all the changes are complete you save the whole lot with one call to Update.
    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
    Hyperactive Member
    Join Date
    Sep 2006
    Posts
    256

    Re: Updating Access Database

    Oh....Thank You very much....

    This works wonders..DataGrid1.DataMember = "books"

    I didn't knew about this binding using .Datamember...

    Thanks a Lot...
    If an answer to your question has been helpful, then please, Rate it!

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