manipulating DataTable

J

John A Grandy

for manipulating a (disconnected) DataTable ,

how to iterate through the rows ?

how to insert a row ? update a row ? delete a row ?

how to perform queries of the DataTable , such as filters and sorts , to
return another DataTable ?
 
M

Miha Markic [MVP C#]

Hi John,

John A Grandy said:
for manipulating a (disconnected) DataTable ,

how to iterate through the rows ?

foreach (DataRow row in table.Rows)
how to insert a row ? update a row ? delete a row ?

DataTable.NewRow/AddRow, DataRow[columnName] = ..., DataRow.Delete
how to perform queries of the DataTable , such as filters and sorts , to
return another DataTable ?


User either DataView or DataTable.Select method.
 
W

William Ryan eMVP

--

W.G. Ryan, eMVP

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
John A Grandy said:
for manipulating a (disconnected) DataTable ,

how to iterate through the rows ?
foreach(DataRow dro in TableName.Rows{
//Do wahtever with dro
}
or
for(int i = 0; i < dt.Rows.Count; i++){
dt.Rows;
}
how to insert a row ?
DataRow dro = myDataTable.NewRow();
myDataTable.Rows.Add(dro);
update a row ?
myDataTable.Rows[Index][ColumnIndex] = "WhateverUpdateValue";
delete a row ?
myDataTable.Rows.Delete[Index];
how to perform queries of the DataTable , such as filters and sorts , to
For all of this you may want to use a DataView as well. Check out my
articles on Efficiently Using ADO.NET xxxx at
http://www.knowdotnet.com/williamryan.html
return another DataTable ?
Not sure what you mean on this one.
 

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

Top