Welcome aboard! We are happy you are here and wish you good net-raft!
// 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;
string sql = null;
MySqlConnection cnn;
MySqlCommand cmd;
MySqlDataReader reader;
connetionString = "server=localhost;database=testDB;uid=root;pwd=xxx;";
sql = "Select * from customers";
cnn = new MySqlConnection(connetionString);
try
{
cnn.Open();
cmd = new MySqlCommand(sql, cnn);
reader = cmd.ExecuteReader();
while (reader.Read())
{
MessageBox.Show(reader.GetValue(0) + " - " + reader.GetValue(1) + " - " + reader.GetValue(2) + " - " + reader.GetValue(3));
}
reader.Close();
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