private void customerLogInToolStripMenuItem_Click(object sender, EventArgs e) { Login a1 = new Login(); a1.MdiParent = this; a1.Show(); }
private void button_Add_Click(object sender, EventArgs e) { SqlConnection connection = new SqlConnection(global::project2v3_csc330.Properties.Settings.Default.PropertyDBConnectionString); try { string sql = "INSERT INTO CustomerTable(Customer_FirstName, Customer_LastName, Customer_Phone, Customer_Email, Customer_UserName, Customer_Password) VALUES ('" + txt_FirstName.Text + "', '" + txt_LastName.Text + "', '" + txt_Phone.Text + "', '" + txt_Email.Text + "', '" + txt_UserName.Text + "', '" + txt_Password1.Text + "')"; SqlCommand commandInsert = new SqlCommand(sql, connection); connection.Open(); commandInsert.ExecuteNonQuery(); int customerid = 0; string sql2 = "SELECT * FROM CustomerTable WHERE Customer_UserName = @username"; SqlCommand getStatuscmd = new SqlCommand(sql2, connection); getStatuscmd.Parameters.AddWithValue("@username", txt_UserName.Text); //connection.Open(); using (SqlDataReader reader = getStatuscmd.ExecuteReader()) { while (reader.Read()) { customerid = Convert.ToInt32(reader["Customer_Id"].ToString()); } } MessageBox.Show("Add new account successfully!\nYour CustomerID is " + customerid, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch(Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { connection.Close(); this.Close(); Login a1 = new Login(); //a1.MdiParent = project2v3_csc330.MainForm; a1.Show(); } }