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
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Soft CornerPosted May 1, 2011, 12:52 PM
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 VatsaPosted May 2, 2011, 7:57 AM
read this