Find specific data row in Dataset

Discussion in 'ASP .Net' started by Grey, Sep 22, 2004.

  1. Grey

    Grey Guest

    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
    Grey, Sep 22, 2004
    #1
    1. Advertising

  2. Grey

    GrantMagic Guest

    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
    }
    }
    }

    "Grey" <> wrote in message
    news:...
    >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
    >
    >
    GrantMagic, Sep 22, 2004
    #2
    1. Advertising

  3. Grey

    Hermit Dave Guest

    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)
    "Grey" <> wrote in message
    news:...
    >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
    >
    >
    Hermit Dave, Sep 22, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Craig
    Replies:
    2
    Views:
    2,874
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Nov 2, 2004
  2. =?Utf-8?B?SnVzdGlu?=

    Updating a specific Row in a DataSet

    =?Utf-8?B?SnVzdGlu?=, Mar 13, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    415
    Karl Seguin
    Mar 13, 2005
  3. IK

    How to find grid's row that matches row in dataset

    IK, Sep 15, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    173
  4. D
    Replies:
    0
    Views:
    206
  5. Giggle Girl

    ie6 Insert Row at specific Row Index of Table

    Giggle Girl, Feb 5, 2006, in forum: Javascript
    Replies:
    18
    Views:
    274
    Thomas 'PointedEars' Lahn
    Feb 7, 2006
Loading...

Share This Page