using MySql.Data.MySqlClient;
using System;
namespace ConsoleMySqlOrnek_1
{
class Program
{
static string cnnStr = @"Server=127.0.0.1;Port=3306;Database=sakila;Uid=root;Pwd=saPass1234;";
static MySqlConnection con;
static void Main(string[] args)
{
try
{
con = new MySqlConnection(cnnStr);
if (con.State== System.Data.ConnectionState.Closed)
{
con.Open();
}
MySqlCommand cmd = new MySqlCommand("SELECT country,city,name " +
"FROM sakila.customer_list order by name LIMIT 10",con);
MySqlDataReader dr =cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
Console.WriteLine("country : " + dr["country"].ToString()
+ ".. city : " + dr["city"].ToString()
+ " .. name : " + dr["name"].ToString() );
}
}
con.Close();
cmd.Dispose();
}
catch (Exception ex)
{
var s = ex.Message;
Console.WriteLine(s);
}
}
}
}
Yorumlar
Yorum Gönder