Skip to content

Compare oledb datareader with textbox data?

honar abubakr

honar abubakr

Asked Jul 26, 2013, 5:40 AM EDT3 answers
Share
LinkedInX

i want to compare oledb datareader data with a textbox data something like this cod.

i have textbox named textbox7 … the datareader have more than one mobile_no

Java
OleDbCommand ol_com = new OleDbCommand(); OleDbDataReader reader; ol_com.CommandText = "select [mobile_no] from student_info"; reader = ol_com.ExecuteReader(); if (reader.Equals(textbox7.text)) {   up_st_lbl2.Text = "error";  }  else   {     //do something  }

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Can you please elaborate your question?

    All the mobile numbers are stored in a single column or multiple columns?

    If it multiple columns and I'm assuming the column names mobile1 and mobile2.

    boolean found = false;
    if (reader.HasRows)
    {
       while(reader.read())
    {
       string mobile1 = reader.get("mobile1");
       string mobile2 = reader.get("mobile2");
        if (txtmobile.Text == mobile1 or txtmobile.Text= mobile2 )
        {
            found = true;
        }
    }
    reader.close();

    ** The code is not tested and try to change according to your needs.
    0
  • honar abubakr
    0
    thank you
    and all mobile numbers are in one column ... as you know mobile number can not repeate i want to compare mobile number column with the textbox that entered a mobile from it?
    0
  • 0
    In the database, do you have multiple numbers are stored in the single column? 
    Can you please give me a sample multiple mobile from database?

     
    boolean found = false;
    if (reader.HasRows)
    {
       while(reader.read())
    {
        string mobileno = Conver.ToString(reader.get("mobile"));
        if (txtmobile.Text.Trim() == mobileno.Trim())
            {
                    found = true;
                     //break; //to stop the iteration
            }
    }
    reader.close();
    }

    If you don't want to iterate the loop once you found the match, add break statement after 
    found = true.

    As soon as it found the first match, again it will not read the data from database.


    ** The code is not tested and try to change according to your needs.
    0