Romilton Fernando
Romilton Fernando

Reputation: 953

i want to check the the given value present in a dataset column or not

I want to check the given value present in a dataset column. I was insert the value using separator and stored in a column name fld empname. Example the dataset field fldempname have the value Hari,vinoth,Arun. suppose i ll insert again the value hari and arun means it display error message Like this Employee name already present otherwise the value inserted. please help me..

My partial code is here..

 for (int i = 0; i < lstbox.Items.Count; i++)
                    {
                        if (lstbox.Items[i].Selected)
                        {
                            string id = lstbox.Items[i].Text;
                            DataSet4TableAdapters.sp_getallattendancesetupTableAdapter TA1 = new DataSet4TableAdapters.sp_getallattendancesetupTableAdapter();
                            DataSet4.sp_getallattendancesetupDataTable DS1 = TA1.GetData();
                            if (DS1.Rows.Count == 0)
                            {
                                employee = employee + lstbox.Items[i].Text + ",";
                            }
                            else if (DS1.Rows.Count > 0)
                            {
                                foreach (DataRow dr in DS1.Rows)
                                {
                                    foreach (string category in dr["fldemployee"].ToString().Split(','))
                                    {
                                        if (category != "")
                                        {
                                            if (category == id)
                                            {
                                                Value = Value + lstbox.Items[i].Text + "\\n";
                                                break;
                                            }
                                        }
                                        continue;

                                    }

                                }
                            }
                        }

Upvotes: 0

Views: 12023

Answers (2)

Rohan B&#252;chner
Rohan B&#252;chner

Reputation: 5393

I haven't worked with datasets in a while.. so there prob is cleaner/better way to do this..

 DataSet st = new DataSet();
 foreach (DataRow row in st.Tables["table_name"].Rows)
 {
      if (row["column_name"] == "value")
      {
         //found
      }
 }

side note: i'd try Mitch Wheat's answer

Upvotes: 0

Mitch Wheat
Mitch Wheat

Reputation: 300489

You can use the DataSet's Select() method:

DataRow[] foundRows; 
foundRows = dataSet1.Tables["MyTable"].Select("fldempname = 'Hari'");

Upvotes: 5

Related Questions