How to compare value from table with textbox value
Hi Experts...I need to compare username field from the table with the textbox value using datareader...Please tell me code...Thanks in advance
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Soft CornerRank #1,221 · 1.5K reputationPosted May 1, 2011, 8:52 AM EDT
Try this Code :
SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=DBNAME;Integrated Security=true;");
SqlDataReader dr;
SqlCommand cmd;
try
{
con.Open();
string qry ="select * from table where username ='"+textbox1.Text+"'";
cmd = SqlCommand(qry,con);
dr = cmd.ExecuteReader();
while(dr.read())
{
//do something
MessageBox.Show("UserName:"+dr.GetString(0));
}
dr.Close();
con.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.message);
}
finally
{
con.Close();
}
Abhimanyu K VatsaRank #14 · 51.7K reputationPosted May 2, 2011, 3:57 AM EDT
read this