I have a grid bound from a mysql db table via c#. Is there any way to get the displayed items in an insert statement?
For ex: If i bind a grid with 20 rows, i need to get all of them in a insert statements, which i can save as a .sql file and run it in another db.
Your thoughs will be highly helpful.
You COULD do it by looping through the grid rows and getting the values of each cell but that would be the hard way to do it. You’d be better off just having the DB do the work by having the DB perform the insert statement using a select statement directly as outlined here:
http://www.sqlteam.com/article/using-select-to-insert-records
This is the normal way to take the results of a select statement and insert into a different table.
Edit My co-worker, who is much smarter than me, figured out how to get the underlying DataTable from the Viewstate and use it as follows (in VB – you will need to translate it to C#):
Edit – added
Here’s another option that’s similar to what it looks like you’re asking, and the code snippet definitely shows how to loop through the rows in a datagrid to get values…
http://www.eggheadcafe.com/articles/20060513.asp