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
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 }
Posted Jul 26, 2013, 3:05 PM
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.
honar abubakrPosted Jul 26, 2013, 2:22 PM
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?
Posted Jul 26, 2013, 1:41 PM
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.