Guest User

Untitled

a guest
May 3rd, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. private void button2_Click(object sender, EventArgs e)
  2. {
  3. try
  4. {
  5. //This is my connection string i have assigned the database file address path
  6. string MyConnection2 = "datasource=localhost;port=3307;username=root;password=root";
  7. //This is my update query in which i am taking input from the user through windows forms and update the record.
  8. string Query = "update student.studentinfo set idStudentInfo= + this.IdTextBox.Text + ,Name= + this.NameTextBox.Text + ,Father_Name= + this.FnameTextBox.Text + ,Age= + this.AgeTextBox.Text + ,Semester= + this.SemesterTextBox.Text + where idStudentInfo= + this.IdTextBox.Text + ;";
  9. //This is MySqlConnection here i have created the object and pass my connection string.
  10. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
  11. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
  12. MySqlDataReader MyReader2;
  13. MyConn2.Open();
  14. MyReader2 = MyCommand2.ExecuteReader();
  15. MessageBox.Show("Data Updated");
  16. while (MyReader2.Read())
  17. {
  18. }
  19. MyConn2.Close();//Connection closed here
  20. }
  21. catch (Exception ex)
  22. {
  23. MessageBox.Show(ex.Message);
  24. }
  25. }
Add Comment
Please, Sign In to add comment