Modifying row in datatable??

  • Thread starter Thread starter VM
  • Start date Start date
V

VM

How can I modify a row in a datatable in a Windows form? For example, I want
to find the row where 'emplcode' equas '000001' and once I find it, change
the 'name' to 'John'. Then put the updated row back to the table.

Thanks.
 
How can I modify a row in a datatable in a Windows form? For example, I want
to find the row where 'emplcode' equas '000001' and once I find it, change
the 'name' to 'John'. Then put the updated row back to the table.

You can find the row with DataTable.Rows.Find().

Once found, simply update the data. You can then get the changed
DataTable via DataTable.GetChanges and pass that to a DataAdapter for
updating.
 
Never mind. I figured it out.

Basically, I retrieve the grid's datasource into a datatable:

DataTable DT_tempTable = (DataTable)dataGrid_auditAddress.DataSource;

do a query of of the table and put the result in a datarow collection:

DataRow[] row_1 = DT_tempTable.Select("col_row = '" + iRowNum.ToString() +
"'");
row_1[0]["col_mark"] = MARKED; //in this case, it always returns one row

Unfortunately, this automatically updates the datagrid also (which takes
ages if processing large amounts of rows), so you need to deattach the grid
datasource, modify the datatable, and reattach once again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top