C# .NET - How to compare values from the datatable to a string value using C#

Asked By Austine on 31-Jan-13 02:27 AM
Hi ,

    I fetched data from the database table and fill them to the datatable.

   I want to search the datatable  for a number ans check is the number is the value of a string i have already.

   If the number matches the string value, i will make use of the number .

   If the number does not match the string values, then nothing happens.

  Am using c# winforms

 Please help.

Thank you
RAJESH VEMUNOORI replied to Austine on 31-Jan-13 04:16 AM
Hi,

If your datatable is dt and string str then..
for(int i=0;i<dt.rows.count;i++)
{
   if(dt.rows[i]["column_name"].tostring() == str)
    {
    response.write("matched");
    }
  else
    {
    response.write("not matched");
    }
}

Let me know if this helped you..

Regards,
Rajesh.
Austine replied to RAJESH VEMUNOORI on 31-Jan-13 05:33 AM
end of post