Click here to Skip to main content
15,885,777 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I want to find out if an input value is equal to one in the datatable. I have used the datarow select method to return all rows in the datatable meeting a certain ID, now i want to loop through these returned rows to find if there is a match between the input value and whats in the datatable. I cant seem to find the proper way to do this. Any help is much appreciated. my code is below:

C#
DataRow[] foundrows = cvmanagerDataSet1.Tables["role"].Select("dept_id = '"+id+"'");
                    foreach(DataRow dr in foundrows)
                         {
                          //  role = foundrows[0].ItemArray[2].ToString();
                            MessageBox.Show(dr["role"]);
                            if (role1.Text == role)
                            {
                                MessageBox.Show("The role '" + role1.Text + "' already exists for this department", "Duplicate role names", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                                //break;
                            }
                            else
                            {
                                addedroles.Items.Add(role1.Text);
                                role1.Text = "";
                                bttnremove.Enabled = true;
                                bttnreset.Enabled = true;
                                bttndone.Enabled = true;
                                break;
                            }
                          }
Posted
Comments
Nish Nishant 11-Feb-11 12:29pm    
You already use foreach. Is it not working as you want it to?
[no name] 11-Feb-11 12:33pm    
no it is not
Nish Nishant 11-Feb-11 12:44pm    
In what way is it not working?

1 solution

Do you mean how to get data out of the DataRow?

C#
foreach (DataRow DR in MyRows)
{
    String Data = DR["Name"] as String;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900