Find specific data row in Dataset

G

Grey

I have a dataset, is it possible to find one specific row of data with some
criteria?? For example There are two fields, Field1 and Field2 in the
datatable of dataset. i need to search is Field1 column has value 'a', if
so, i need to get the data of Field2.

Million thanks
 
G

GrantMagic

You can loop through a dataset to find that value

DataSet ds = new DataSet("table");
//FILL THE DATASET
string RequiredValue;

foreach(DataRow dr in ds.Table["tale"].Rows)
{
if(dr[0].ToString == "a") //WHERE 0 is the field1
{
RequiredValue = dr[1].ToString(); //WHERE 1 is field2
}
}


If you don't know the name of the datatable before hand, you can loop
through those too

foreach(DataTable dt in ds.Tables)
{
foreach(DataRow dr in dt.Rows)
{
if(dr[0].ToString == "a") //WHERE 0 is the field1
{
RequiredValue = dr[1].ToString(); //WHERE 1 is field2
}
}
}
 
H

Hermit Dave

DataRows[] drFiltered =
yourDataSet.Tables[0].Select("yourcolumnfiltercriteria");
if drFiltered.Length != 0 then you know you have the records filtered.

yourcolumnfiltercriteria could be
your columnname with any of the operators = != > < >= <= etc etc. look it up

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top