A very easy way to connect ASP.NET application to use MySQL database is to use the MySQL Net Connector. With just the following lines of code, you can easily hookup your ASP.NET application to any MySQL db.
public static string GetConnectionString()
{
string connStr = String.Format("server=hostname;user id=dbname; password=password;database=dbname; pooling=false", "hostname", "dbname", "password");
return connStr;
}
protected void btnProceed_OnClick(object sender, EventArgs e)
{
MySql.Data.MySqlClient.MySqlConnection mycon = new MySqlConnection(GetConnectionString());
if (mycon.State != ConnectionState.Open)
{
try
{
mycon.Open();
string strQuery = "select * from table";
MySqlDataAdapter adapter = new MySqlDataAdapter(strQuery, mycon);
DataSet myDataSet = new DataSet();
adapter.Fill(myDataSet, "mytable");
}
catch (MySqlException ex)
{
throw (ex);
}
}
}
If you think this post is useful, please recommend me at the bottom of the page. ;)