Friday, April 17, 2009

ADO.NET (PART 7)


         HOW TO LOGIN THROUGH DATABASE 

DATABASE:
NAME = Northwind.

TABLE :
NAME = Login.

FIELDS:

username,password.


private void BtnLogin_Click(object sender, EventArgs e)
  {
  SqlConnection cn = new SqlConnection("Data Source=.;Initial Catalog=Northwind;Integrated Security=True");
  SqlDataAdapter da = new SqlDataAdapter("select * from login", cn);
  SqlCommand cmd = new SqlCommand();
  cmd.Connection= cn;
  cmd.CommandText = "select *from login where username = '" + txtUser.Text + " ' and password = '" + txtPwd.Text + "'";
  cmd.Connection.Open();
  SqlDataReader dr;
  dr=cmd.ExecuteReader();
  if(dr.Read())
  {
  Form1 f = new Form1();
  f.Show();
  this.Hide();
  }
  else
  {
  MessageBox.Show( "Invalid UserName or Password!!","invalid");
  }

}

No comments:

Post a Comment