private void btn_login_Click(object sender, EventArgs e) { username = txt_username.Text; u = username; password = txt_password.Text; if (username == "admin" && password == "admin") { Admin_home ah = new Admin_home(); this.Hide(); ah.Show(); } else { //sql connection SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Product_Management;Integrated Security=true"); //to call stored procedure SqlCommand cmd = new SqlCommand("login_data", con); cmd.CommandType = CommandType.StoredProcedure; //pass the value to the stored procedure cmd.Parameters.AddWithValue("@username", username); cmd.Parameters.AddWithValue("@password", password); //execute stored procedure con.Open(); int i = (int)cmd.ExecuteScalar(); if (i > 0) { User_home uh = new User_home(); this.Hide(); uh.Show(); } else { MessageBox.Show("Invalid username & password"); } } }
private void btn_update_Click(object sender, EventArgs e) { con.Close(); email = txt_email.Text; phone = txt_phone.Text; cmd = new SqlCommand("update_data", con); cmd.CommandType = CommandType.StoredProcedure; //to pass values to the stored procedure cmd.Parameters.AddWithValue("@username", user); cmd.Parameters.AddWithValue("@email", email); cmd.Parameters.AddWithValue("@phone", phone); //execute stored procedure con.Open(); cmd.ExecuteNonQuery(); MessageBox.Show("Data updated"); User_home uh = new User_home(); //this.Hide(); uh.ShowDialog(); }