Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you loop thru a DataView ?

Status
Not open for further replies.

TerDavis

Technical User
Sep 18, 2002
36
0
0
US
Hi,

I have a dataview and want to extract some
values out of it...
So how do I Loop thru a DataView to find a row which
has a particular value for a column and then
how do i delete that row from the DataView ??

Thanks,
Ter
 
Try this:

Code:
DataView dv = new DataView ();
string value1 = "";
string value2 = "";

foreach (DataRowView drv in dv)
{
   value1 = drv ["value1"].ToString ();
   value2 = drv ["value2"].ToString ();
}

- VB Rookie
 
DataView supports searching using the Find and FindRows methods.
Ex for Find:

DataView vue = new DataView(tbl);
vue.Sort = "ContactName";
int intIndex = vue.Find("Fran Wilson");
if (intIndex == -1)
Console.WriteLine("Row not found!");
else
Console.WriteLine(vue[intIndex]["CompanyName"]);

Or(for FindRows ):

DataView vue = new DataView(tbl);
vue.Sort = "Country";
DataRowView[] aRows = vue.FindRows("Spain");
if (aRows.Length == 0)
Console.WriteLine("No rows found!");
else
foreach (DataRowView row in aRows)
Console.WriteLine(row["City"]);

For deleting a row in a DataView after finding it:

//Delete a row.
row.Delete();

Hope this help you,
Mary
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top