똑똑해진느낌/C#

[C#] MySQL DB를 DataSet으로 담기

찐쿵 2019. 8. 26. 14:22

MySQL DB를 DataSet에 담는 코드입니다.

using MySql.Data.MySqlClient;

private DataSet ds = new DataSet();
private string SQLConnStr = "Server=127.0.0.1;Uid=root;Pwd=****;Database=db";

public DataSet GetDataSet(string ConnectionString, string SQL, string ds_table)
{
    MySqlConnection conn = new MySqlConnection(ConnectionString);
    MySqlDataAdapter da = new MySqlDataAdapter();
    MySqlCommand cmd = conn.CreateCommand();
    cmd.CommandText = SQL;
    da.SelectCommand = cmd;
    conn.Open();
    da.Fill(ds, ds_table);
    conn.Close();

    return ds;
}