Click here to Skip to main content
13,004,446 members (74,491 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have a datagridview view that looks like this:

ProductId | Name | Price | Quantity

The datagridview starts with all cells empty.

The user will enter data in each of the columns. The number of products the user enters changes(is unknown). The user could enter only one product or five products.

So, once the user has entered all the products he has to enter, i want that when he clicks a button, all products will be saved to the database.

The table in the SQL database looks like the datagrid:

ProductId | Name | Price | Quantity

As the number of products that the user will enter is unknown, how can I save the data to the database?

[Edit]Shouting removed[/Edit]
Posted 12-Feb-13 7:07am
Updated 12-Feb-13 7:08am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Just treat each product as an individual item and just loop through each product that needs to be inserted and do it.
Dealing with multiple rows is pretty much exactly the same as dealing with individual rows of data. The only difference is that multiple rows are dealt with in a loop of some kind.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

On inserting new row in datagridview save that row's value in datatable and then save that datatable to viewstate["dt"].On each insert new row( i.e. insert command), Bind datagridview with datatable which saved in viewstate["dt"] .your all data come in the viewstate["dt"].You can make loop on this viewState["dt"] to add save data in database.
Zain -Ul- Arifeen 13-Feb-13 11:07am
dear sir,
if u will guid me on this question with code or demo.
that is better for me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170627.1 | Last Updated 12 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100