private void button_logout_Click(object sender, EventArgs e) { this.Hide(); New_food_item fl = new New_food_item(); fl.Close(); }
private void button1_Click(object sender, EventArgs e) { if (text_User_name.Text == "" || tex_Password.Text == "") { MessageBox.Show("Please provide UserName and Password"); return; } try { //Create SqlConnection SqlConnection con = new SqlConnection("Data Source=MAZHARUL\\SQLEXPRESS;Initial Catalog=Log;Integrated Security=True"); SqlCommand cmd = new SqlCommand("Select * from SingUp where User_Name='" + text_User_name.Text + "' and Password='******'", con); //cmd.Parameters.AddWithValue("@username", text_User_name.Text); //cmd.Parameters.AddWithValue("@password",tex_Password.Text); con.Open(); SqlDataAdapter adapt = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adapt.Fill(ds); con.Close(); int count = ds.Tables[0].Rows.Count; //If count is equal to 1, than show New_food form if (count == 1) { MessageBox.Show("Login Successful!"); this.Hide(); New_food_item fm = new New_food_item(); fm.Show(); } else { MessageBox.Show("Login Failed!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }