//private void btn_signup_Click(object sender, EventArgs e) //{ // DBcon.con.Open(); // cmd.ExecuteNonQuery(); // DBcon.con.Close(); //} private void Login_Signup_Load(object sender, EventArgs e) { LogOutStatus = false; panel_login.Hide(); Signup_panel.Hide(); //Data Source=DESKTOP-0VTF41Q\SQLEXPRESS;Initial Catalog=TheProject;Integrated Security=True conString = "Data Source=" + ServerName + "" + ";Initial Catalog=TheProject;Integrated Security=True"; if (!CheckDBExists(conString)) { Signup_panel.Show(); } else { conString = "Data Source=" + ServerName + "" + ";Initial Catalog=TheProject;Integrated Security=True"; FinalCon.ConnectionString = conString; panel_login.Show(); } }
private void SignUp_button_Click(object sender, EventArgs e) { string username = textBox_username_signup.Text; string pass = textBox_pass_signup.Text; string repass = textBox_conPass_signup.Text; if (pass != repass) { label_Status_signup.ForeColor = Color.Red; label_Status_signup.Text = "Password Not Matched"; return; } conString = "Data Source=" + Environment.MachineName + "" + ";Initial Catalog=;Integrated Security=True"; SqlConnection Connection = new SqlConnection(conString); string script = File.ReadAllText(@"..\..\Scripts\script.sql"); // split script on GO command IEnumerable <string> commandStrings = Regex.Split(script, @"^\s*GO\s*$", RegexOptions.Multiline | RegexOptions.IgnoreCase); Connection.Open(); foreach (string commandString in commandStrings) { if (!string.IsNullOrWhiteSpace(commandString.Trim())) { using (var command = new SqlCommand(commandString, Connection)) { command.ExecuteNonQuery(); } } } Connection.Close(); conString = "Data Source=" + ServerName + "" + ";Initial Catalog=TheProject;Integrated Security=True"; FinalCon.ConnectionString = conString; //if (pass == repass) { string sq = @"insert into LoginInfoTable values(@NewName,@NewPass,1)"; SqlCommand dbCommand = new SqlCommand(sq, FinalCon); dbCommand.Parameters.AddWithValue("@NewName", username); dbCommand.Parameters.AddWithValue("@NewPass", pass); // SqlCommand cmd1 = new SqlCommand(); // cmd1.Connection = FinalCon; // cmd1.CommandText = "'" + username + "','" + pass + "',1)"; FinalCon.Open(); dbCommand.ExecuteNonQuery(); FinalCon.Close(); // cmd1.CommandText = "insert into LoginInfoTable values('" + username + "','" + pass + "',1)"; // FinalCon.Open(); // cmd1.ExecuteNonQuery(); // FinalCon.Close(); Signup_panel.Hide(); panel_login.Show(); label_Status_signup.ForeColor = Color.Green; label_Status_signup.Text = "Registered Successfully"; } }