|
-
May 14th, 2013, 08:35 PM
#1
Thread Starter
Addicted Member
-
May 14th, 2013, 08:52 PM
#2
Re: Saving Items From Datagridview to Database?
If you're using a MySQL then, if you haven't already, you should first install Connector/Net, which is a freely downloadable, MySQL-specific ADO.NET provider. You can then reference the MySql.Data.dll assembly in your application project.
In code, use a MySqlDataAdapter to Fill a DataTable with the data from the database and bind that table to your DataGridView via a BindingSource. Once you've made your changes, use the same adapter to Update the database with the changes from the table. For a code example of the data access part, follow the CodeBank link in my signature and check out my thread on Retrieving & Saving Data.
-
May 14th, 2013, 10:12 PM
#3
Thread Starter
Addicted Member
Re: Saving Items From Datagridview to Database?
Thanks for the reply.
I do have the MySQL Connector/Net setup with my database. I know How to Update, Insert, Save, and Delete.
It is just, like this scenario:
When I click Save Receipt, the Application Generates a receipt Number
So, Receipt # 1 has 50 items on it,
How would 50 items on the receipt get saved to the database?
Would I create a Table for each receipt # created in the Database, and the rows are the items?
-
May 14th, 2013, 10:20 PM
#4
Re: Saving Items From Datagridview to Database?
You would have one table for the receipt records and one table for the items on the receipts. There are numerous examples around like this, including the Order and OrderDetail tables in the Northwind and AdventureWorks example databases from Microsoft. For instance, you might have a Receipt table with a ReceiptID column as primary key. You might also have a ReceiptItem table with a ReceiptItemID column as primary key and a ReceiptID column as a foreign key from the Receipt table. If you save a Receipt record with a ReceiptID of 1 then you save all the items on that receipt to the ReceiptItem table with a ReceiptID of 1. You can then get all the items on a receipt by specifying the appropriate foreign key value to filter the data.
-
May 27th, 2013, 12:53 AM
#5
Thread Starter
Addicted Member
Re: Saving Items From Datagridview to Database?
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
|