728x90

아래 명령으로 MySQL연결 DLL를 추가한다.

dotnet add package MySqlConnector

 

아래 예시처럼 사용한다.

 
    using MySqlConnector;
 
    string connectionString = "Server=localhost;Database=mysql;Uid=root;Pwd=pwd;";
    MySqlConnection conn = new MySqlConnection(connectionString);
    conn.Open();

    string sql = "select * from user";
    MySqlCommand cmd = new MySqlCommand();
    cmd.CommandText = sql;
    cmd.Connection = conn;

    MySqlDataAdapter da = new MySqlDataAdapter();
    da.SelectCommand = cmd;

    DataSet ds = new DataSet();
    da.Fill(ds, "std");
 
728x90
반응형

+ Recent posts