Advertisement
Guest User

Untitled

a guest
Oct 14th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. private void regusr_button_Click(object sender, EventArgs e)
  2. {
  3. string secure = "";
  4. if (protectusr_checkbox.Checked == true)
  5. {
  6. secure = "Yes";
  7. } else
  8. {
  9. secure = "No";
  10. }
  11. string studyplan = "";
  12. if (trimester_radiobutton.Checked == true)
  13. {
  14. studyplan = "Trimester";
  15. }
  16. else if (semester_radiobutton.Checked == true)
  17. {
  18. studyplan = "Semester";
  19. }
  20. try
  21. {
  22. //This is my connection string i have assigned the database file address path
  23. string MyConnection2 = "datasource=localhost;port=3307;username=root;password=root";
  24. //This is my insert query in which i am taking input from the user through windows forms
  25. 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 + "');";
  26. //This is MySqlConnection here i have created the object and pass my connection string.
  27. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
  28. //This is command class which will handle the query and connection object.
  29. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
  30. MySqlDataReader MyReader2;
  31. MyConn2.Open();
  32. MyReader2 = MyCommand2.ExecuteReader(); // Here our query will be executed and data saved into the database.
  33. MessageBox.Show("Save Data");
  34. while (MyReader2.Read())
  35. {
  36. }
  37. MyConn2.Close();
  38. }
  39. catch (Exception ex)
  40. {
  41. MessageBox.Show(ex.Message);
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement