ابتدا دات نت اسمبلی MySqlConnector.Net رو دانلود و Add کنین ،
حال اگر به فرض فایل DAL مون کلاسی به شکل زیر داشته باشیم :
public class Dal
{
private SqlConnection conn = new SqlConnection("Server=removed,1430;Database=remove d;User ID=removed;Password=removed;Trusted_Connection=Fal se;");
private SqlCommand cmd = new SqlCommand();
private SqlDataAdapter adap = new SqlDataAdapter();
private SqlDataReader dr;
public SqlDataReader Dr
{
get { return dr; }
set { dr = value; }
}
public SqlDataAdapter Adap
{
get { return adap; }
set { adap = value; }
}
public SqlCommand Cmd
{
get { return cmd; }
set { cmd = value; }
}
public SqlConnection Conn
{
get { return conn; }
set { conn = value; }
}
}
برا MySql کافی هست اون رو به این شکل تغییر بدیم:
// using MySql.Data.MySqlClient
public class Dal
{
private MySqlConnection conn = new MySqlConnection("server={localhost};user id={root}; password={}; database=db_blog; pooling=false"");
private MySqlCommand cmd = new MySqlCommand();
private MySqlDataAdapter adap = new MySqlDataAdapter();
private MySqlDataReader dr;
public MySqlDataReader Dr
{
get { return dr; }
set { dr = value; }
}
public MySqlDataAdapter Adap
{
get { return adap; }
set { adap = value; }
}
public MySqlCommand Cmd
{
get { return cmd; }
set { cmd = value; }
}
public MySqlConnection Conn
{
get { return conn; }
set { conn = value; }
}
}