Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void regusr_button_Click(object sender, EventArgs e)
- {
- string secure = "";
- if (protectusr_checkbox.Checked == true)
- {
- secure = "Yes";
- } else
- {
- secure = "No";
- }
- string studyplan = "";
- if (trimester_radiobutton.Checked == true)
- {
- studyplan = "Trimester";
- }
- else if (semester_radiobutton.Checked == true)
- {
- studyplan = "Semester";
- }
- try
- {
- //This is my connection string i have assigned the database file address path
- string MyConnection2 = "datasource=localhost;port=3307;username=root;password=root";
- //This is my insert query in which i am taking input from the user through windows forms
- string Query = "insert into user.userinfo(universityName,userCarrer,userFirstName,userLastName,studyPlan,startDate,finishDate,secureUser,userPassword) values('" + this.uniname_textbox.Text + "','" + this.carrer_name.Text + "','" + this.usr_firstname_textbox.Text + "','" + this.usr_lastname_textbox.Text + "','" + studyplan + "','" + init_date + "','" + finish_date + "','" + secure + "','" + this.usrpswrd_textbox.Text + "');";
- //This is MySqlConnection here i have created the object and pass my connection string.
- MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
- //This is command class which will handle the query and connection object.
- MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
- MySqlDataReader MyReader2;
- MyConn2.Open();
- MyReader2 = MyCommand2.ExecuteReader(); // Here our query will be executed and data saved into the database.
- MessageBox.Show("Save Data");
- while (MyReader2.Read())
- {
- }
- MyConn2.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement