|
-
Jun 9th, 2016, 06:11 AM
#1
Thread Starter
New Member
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
-
Jun 9th, 2016, 08:12 AM
#2
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.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|