Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class Form1 : Form
- {
- MySqlConnection conn;
- string connString;
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- connString = "SERVER= myServerIP;PORT=3306;DATABASE=databaseName;UID=myUsername;PASSWORD=myPassword;";
- try
- {
- conn = new MySqlConnection();
- conn.ConnectionString = connString;
- conn.Open();
- MessageBox.Show("connection success");
- }
- catch (MySql.Data.MySqlClient.MySqlException ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
- using System;
- using System.Windows.Forms;
- using MySql.Data.MySqlClient;
- public partial class Form1 : Form
- {
- string connString;
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- connString = "SERVER= myServerIP;PORT=3306;DATABASE=databaseName;UID=myUsername;PASSWORD=myPassword;";
- try
- {
- string Query = "insert into person.personinfo(ID,Name,Email) values('" + this.textBox1.Text + "','" + this.textBox2.Text + "','" + this.textBox3.Text + "');";
- MySqlConnection MyConn2 = new MySqlConnection(connString);
- MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
- MySqlDataReader MyReader2;
- MyConn2.Open();
- MyReader2 = MyCommand2.ExecuteReader();
- MessageBox.Show("Data Updated");
- while (MyReader2.Read())
- {
- }
- MyConn2.Close();
- }
- catch (MySql.Data.MySqlClient.MySqlException ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
Add Comment
Please, Sign In to add comment