Monday, September 28, 2009

how to compare the texbox content with the database

using System.Data.SqlClient;

public partial class checklogin : System.Web.UI.Page
{
public void Page_Load(object sender, EventArgs e)
{

}
public void btncheck_Click(object sender, EventArgs e)
{
try
{
SqlConnection cn = new SqlConnection("Data Source=SARAT-B2A64D7C6;Initial Catalog=sarat;Integrated Security=True");
cn.Open();
SqlCommand cmd = new SqlCommand("select * from emp", cn);

SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
lb1.Text = dr[1].ToString();//here the dr[1] represent the second colum of the table depending on ur requirement u can change it as appropiate
if(txt1.Text.Trim()== lb1 .Text .Trim ())
{
lbl.Text = "hi"+txt1 .Text ;
break;
}
else
{
lbl.Text = "get out idiot";
}
}
cn.Close();
dr.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);

}



}
}

If u have any query please bing me no problem i am here to learn and know new thing thanks

No comments:

Post a Comment