Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void button1_Click(object sender, EventArgs e)
- {
- con = new SqlConnection(@"Data Source=MARIA-PC;Initial Catalog=Account;Integrated Security=True");
- SqlCommand cmd1 = new SqlCommand("SELECT * FROM [dbo].[Cont] WHERE Username = @Username and Password = @Password;", con);
- cmd1.Parameters.AddWithValue("@Username", this.Username.Text);
- cmd1.Parameters.AddWithValue("@Password", this.Password.Text);
- cmd1.Connection = con;
- con.Open();
- DataSet ds = new DataSet();
- SqlDataAdapter da = new SqlDataAdapter(cmd1);
- da.Fill(ds);
- con.Close();
- bool loginSuccessful = ((ds.Tables.Count > 0) && (ds.Tables[0].Rows.Count > 0));
- if (loginSuccessful )
- {
- MessageBox.Show("You logged in successfully!","Success!");
- this.Visible = false;
- f3.ShowDialog();
- this.Visible = true;
- }
- else
- {
- MessageBox.Show("Invalid username or password!", "Error!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement