LOGIN CODE SAMPLE FOR C#

SqlConnection sconn = new SqlConnection("User ID=Username;Password=Password;Initial Catalog=DB Name;Data Source=ServerName/IP");

            Form1 formOne = new Form1();
            Successful SuccessForm = new Successful();
            sconn.Open();
             DataSet ds = new DataSet();
             SqlDataAdapter da = new SqlDataAdapter("select * from users where username ='" + TxtUsr.Text + "' and password='" + TxtPwd.Text + "'", sconn);
             da.Fill(ds);
             int count = ds.Tables[0].Rows.Count;
               if(count==0)
             {
                 MessageBox.Show("Invalid UserID/Password");
             }
             else
             {
                 this.Visible = false;
                 SuccessForm.Visible = true;
             }
             sconn.Close();

No comments:

Post a Comment