Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 12-Feb-13 7:08am
v2

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.
 
Share this answer
 
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.
 
Share this answer
 
Comments
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.
thanx

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900