Advertisement
Guest User

Untitled

a guest
Aug 10th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using MySql.Data.MySqlClient;
  10.  
  11. namespace Database_Buddy
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void button3_Click(object sender, EventArgs e)
  21.         {
  22.             textBox1.Text = "";
  23.             textBox2.Text = "";
  24.             textBox3.Text = "";
  25.             textBox4.Text = "";
  26.             textBox5.Text = "Query to be run";
  27.         }
  28.  
  29.         private void button1_Click(object sender, EventArgs e)
  30.         {
  31.             if (textBox1.Text == "")
  32.             {
  33.                 // run code later
  34.             }
  35.             else
  36.             {
  37.                 string host = textBox1.Text;
  38.                 string username = textBox2.Text;
  39.                 string name = textBox3.Text;
  40.                 string password = textBox4.Text;
  41.                 string query = textBox5.Text;
  42.                 if (query == "")
  43.                 {
  44.                     // we're going to show the user the result
  45.                     textBox6.Text = "Query was left empty";
  46.                 }
  47.                 else
  48.                 {
  49.                     MySqlConnection connection = new MySqlConnection("server=" + host + ";database=" + name + ";uid=" + username + ";password=" + password + "");
  50.                     MySqlCommand command = connection.CreateCommand();
  51.                     connection.Open();
  52.                     MySqlCommand command2 = new MySqlCommand("" + query + "", connection);
  53.                     textBox6.Text = "Error connection";
  54.                     command2.ExecuteNonQuery();
  55.                     connection.Close();
  56.                     textBox6.Text = "Query should be complete!";
  57.                 }
  58.             }
  59.         }
  60.  
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement