Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. public void InsertInto(string qs_insert)
  2. {
  3. try
  4. {
  5. conn = new MySqlConnection(cs);
  6. conn.Open();
  7.  
  8. cmd = new MySqlCommand();
  9. cmd.Connection = conn;
  10. cmd.CommandText = qs_insert;
  11. cmd.ExecuteNonQuery();
  12. }
  13. catch (MySqlException ex)
  14. {
  15. MessageBox.Show(ex.ToString());
  16. }
  17. finally
  18. {
  19. if (conn != null)
  20. {
  21. conn.Close();
  22. }
  23. }
  24. }
  25.  
  26. using(MySqlConnection conn = new MySqlConnetion(cs)
  27. {
  28. conn.open();
  29. //setup and execute query
  30.  
  31. } //conn gets closed here
  32.  
  33. public void insert_command(string username, string password, string fullname)
  34. {
  35. using (var con = new MySqlConnection { ConnectionString = "Your Connection String.." })
  36. {
  37. using (var command = new MySqlCommand { Connection = con })
  38. {
  39. con.Open();
  40.  
  41. command.CommandText = @"INSERT INTO usertable SET username=@username, password=@password, fullname=@fullname";
  42. command.Parameters.AddWithValue("@usename", username);
  43. command.Parameters.AddWithValue("@password", password);
  44. command.ExecuteNonQuery();
  45. command.Parameters.Clear();
  46.  
  47. } // command close
  48.  
  49. } // connection close
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement