mysql c# code example
Example 1: c# mysql query
MySqlConnection con = new MySqlConnection(connectionString);
con.Open();
MySqlCommand cmd = new MySqlCommand("SELECT * FROM customers",con);
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader["customerName"].ToString());
Console.WriteLine(reader.GetInt32(0));
}
con.Close();
Example 2: c# select Mysql
DataSet ds = new DataSet();
using (MySqlConnection con = new MySqlConnection(connectionstr))
{
using (MySqlCommand cmd = con.CreateCommand())
{
con.Open();
cmd.CommandText = "select * from mysql.user;";
MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
adapter.Fill(ds);
}
}