Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
3.67/5 (3 votes)
See more:
I have a datagridview with some data input into it, this datagridview hasn't been bound to any datasource (by assigning the DataSource property to some datasource). But now (after inputting some things into the datagridview), I want all data that the datagridview currently contains to be saved or stored in a datatable (an instance of the class DataTable), how can I do that?
Thank you so much!
Posted

You have to loop through cells and add it to datatable.
http://www.daniweb.com/software-development/csharp/threads/209616[^]
 
Share this answer
 
Comments
[no name] 15-Apr-11 20:34pm    
What a helpful link! Thank you!
Try this
C#
datarow drow;
GridViewRow grow;
for(int i=0;i<gridview1.rows.count;i++)>
{
   grow= GridView1.SelectedRow(i);
   drow=dt.rows.find(grow["SomeId"]);
   drow.beginedit();
    drow["Fieldname"]=grow[2];
    drow["Fieldname2"]=grow[3];
     ----
    drow.endedit(); 
}
 
Share this answer
 
v2
Comments
Sandeep Mewara 15-Apr-11 8:32am    
Always use PRE tags to format code part.
Sridhar Patnayak 15-Apr-11 8:42am    
Thanks for your information
Sandeep Mewara 15-Apr-11 8:45am    
:thumbs up:
[no name] 15-Apr-11 20:37pm    
Thanks! Have you tested your code?
I don't see it can work!

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