Results 1 to 2 of 2

Thread: Updating Dataset and database

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2016
    Posts
    5

    Updating Dataset and database

    Hallo,

    Can any one please help me by providing a small example of how to insert data into dataset and then update the original database.
    I am using .accdb database.

    I have already created a new project in Visual studio and then Project -> Add new data source -> Database -> Dataset -> new connection created.

    Your help will be really appreciated.

    Thank you in advance.

    Regard's,
    Pratik

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

    Re: Updating Dataset and database

    If you have created a Data Source then the easiest option from there is to simply drag a table from the Data Sources window onto your form. That will create all the objects you need and most, if not all, the code too. You'll end up with a table adapter and some code that will call its Fill method in the form's Load event handler, which will retrieve the data from the database and populate a DataTable.

    That DataTable will be bound to a BindingSource and that to a DataGridView by default. The user will be able to edit the data in the grid, adding, editing and deleting rows as desired. They will then click the Save button the BindingNavigator that gets added to the form and that will call UpdateAll on a table adapter manager to save the changes back to the database.

    One thing to note is that, by default, every time you build your project, the source database in the project folder gets copied to the output folder, which will overwrite any changes you made to that working database during the last run. If you want to retain those changes between sessions then you can select the database in the Solution Explorer, open the Properties window and set the Copy To Output Directory property to Copy If Newer. That way, the working database will only be overwritten when you make changes to the source file, by either changing the data or the schema.
    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

Tags for this Thread

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