Hi,
I am creating a DataTable object which i am populating it with data from database and binding it to gridview control... I want to update,delete rows in this DataTable object without affecting the Datain my sql table and also bind this DataTable object to Gridview.. How to do this?
Loading

Datta KharadPosted Jan 11, 2012, 5:55 AM
//Adding rows into Datatable:-
DataRow row = null;
for (int i = 0; i < 5; i++)
{
row = dTable.NewRow();
row["AutoID"] = i + 1;
row["Name"] = i + " - Datta";
row["Address"] = "Mumbai, India - " + i;
dTable.Rows.Add(row);
}
//Modify certain values into the DataTable:-
dTable.Rows[2]["AutoID"] = 20;
dTable.Rows[2]["Name"] = "Modified";
dTable.Rows[2]["Address"] = "Modified Address";
dTable.AcceptChanges();
// Delete row:-
dTable.Rows[1].Delete();
dTable.AcceptChanges();
//OR
foreach( DataRow row in someTable.Rows )
{
if( /* your condition here */ )
row.Delete();
}
someTable.AcceptChanges(); //You then need to call AcceptChanges() on the data table to finalize the delete - presumably
//Filtering data from DataTable:-
DataRow[] rows1 = dTable.Select(" AutoID > 5", "AuotID ASC");
//For more detail of Datatable operation refer this link:-
http://www.dotnetfunda.com/articles/article131.aspx
Krishna GaradPosted Jan 11, 2012, 5:46 AM