Search DataSet for a string value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • denny1824
    New Member
    • Dec 2007
    • 32

    Search DataSet for a string value

    I have a DataSet that is filled from a sql select statement that returns one table and most likely just a few rows.

    I need a way to search the second column of the table in the DataSet to see if any of the rows match a specific string.

    This is coded in C#.Net in a windows application.

    Code:
    DataSet ds = new DataSet();
    SqlCommand cmd = new SqlCommand(selectString, conn);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.Fill(ds);
    Thanks for any advice or direction,
    denny1824
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    I'm not hugely experienced with this but...

    Wouldn't it be more correct to do another query on the database with a more specific selectString?

    Comment

    • denny1824
      New Member
      • Dec 2007
      • 32

      #3
      The searching of the DataSet will be done in a loop, with a different string each iteration. I don't want to be hitting the database that many times when I already have the data I just need a way to verify if the string is in the DataSet.

      Comment

      • denny1824
        New Member
        • Dec 2007
        • 32

        #4
        I was able to come up with a solution.

        Code:
        foreach (DataRow row in ds.Tables[0].Rows)
           {
           if (row.ItemArray[1].ToString() == searchString)
              {
              blnFound = true;
              }
           }

        Comment

        Working...