Guest User

Untitled

a guest
Jan 17th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. public partial class Form1 : Form
  2. {
  3. MySqlConnection conn;
  4. string connString;
  5.  
  6. public Form1()
  7. {
  8. InitializeComponent();
  9. }
  10.  
  11. private void button1_Click(object sender, EventArgs e)
  12. {
  13. connString = "SERVER= myServerIP;PORT=3306;DATABASE=databaseName;UID=myUsername;PASSWORD=myPassword;";
  14.  
  15. try
  16. {
  17. conn = new MySqlConnection();
  18. conn.ConnectionString = connString;
  19. conn.Open();
  20. MessageBox.Show("connection success");
  21. }
  22. catch (MySql.Data.MySqlClient.MySqlException ex)
  23. {
  24. MessageBox.Show(ex.Message);
  25. }
  26. }
  27. }
  28.  
  29. using System;
  30. using System.Windows.Forms;
  31. using MySql.Data.MySqlClient;
  32.  
  33. public partial class Form1 : Form
  34. {
  35. string connString;
  36.  
  37. public Form1()
  38. {
  39. InitializeComponent();
  40. }
  41.  
  42. private void button1_Click(object sender, EventArgs e)
  43. {
  44. connString = "SERVER= myServerIP;PORT=3306;DATABASE=databaseName;UID=myUsername;PASSWORD=myPassword;";
  45.  
  46. try
  47. {
  48. string Query = "insert into person.personinfo(ID,Name,Email) values('" + this.textBox1.Text + "','" + this.textBox2.Text + "','" + this.textBox3.Text + "');";
  49.  
  50. MySqlConnection MyConn2 = new MySqlConnection(connString);
  51. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
  52. MySqlDataReader MyReader2;
  53. MyConn2.Open();
  54. MyReader2 = MyCommand2.ExecuteReader();
  55. MessageBox.Show("Data Updated");
  56. while (MyReader2.Read())
  57. {
  58. }
  59. MyConn2.Close();
  60. }
  61. catch (MySql.Data.MySqlClient.MySqlException ex)
  62. {
  63. MessageBox.Show(ex.Message);
  64. }
  65. }
  66. }
Add Comment
Please, Sign In to add comment