Welcome aboard! We are happy you are here and wish you good net-raft!
// I have made a one repair. This code works.
using System;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string connetionString = null;
string sql = null;
MySqlConnection cnn;
MySqlCommand cmd;
connetionString = "server=localhost;database=testDB;uid=root;pwd=xxx;";
sql = "Here put your SQL statement"; // UPDATE, DELETE, INSERT ...
cnn = new MySqlConnection(connetionString);
try
{
cnn.Open();
cmd = new MySqlCommand(sql, cnn);
cmd.ExecuteNonQuery();
cmd.Dispose();
cnn.Close();
MessageBox.Show ("SQL statement is executed!");
}
catch (Exception ex)
{
MessageBox.Show("The connection is refused!");
}
}
}
}
// add reference MySgl.Data
using System;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string connetionString = null;
MySqlConnection cnn ;
connetionString = "server=localhost;database=testDB;uid=root;pwd=xxx;";
sql = "Here put your SQL statement" // UPDATE, DELETE, INSERT ...
cnn = new MySqlConnection(connetionString);
try
{
cnn.Open();
cmd = new MySqlCommand(query, connection);
cmd.ExecuteNonQuery();
cmd.Dispose();
cnn.Close();
MessageBox.Show ("SQL statement is executed!");
}
catch (Exception ex)
{
MessageBox.Show("The connection is refused!");
}
}
}
}
The most helpful C# solutions
detect ie C#C# Click to see more ... 4.7K 853