Can anyone help me to clarify that how to connect mysql server with asp.net and all the relevant query command like select,insert etc. regards shashi
+4
A:
You need to download the MySQL Connector .Net, and install it.
Then, instead of using a SqlProvider for your application, you change it to a MySQL Provider, and add a reference to the MySQL.Data assembly that was installed by the connector to your project. Then add a connection string like usual to your web.config file:
<connectionStrings>
<add name="myConnString"
connectionString="Server=yy;Database=xx;Uid=zzz;Pwd=abcdefg;"
providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
After that it's pretty much the same. The provider model means that the MySQL connector provides all the same objects that you're used to, like MySQLConnection, MySQLCommand, etc.
MySqlConnection conn;
using(conn=new MySqlConnection(ConnectionString)){
MySqlCommand cmd = new MySqlCommand("SELECT * FROM myTable");
conn.Open();
var reader = cmd.ExecuteReader();
/* process records.... */
conn.Close();
}
womp
2009-12-17 04:15:27
+1. You will also need `using MySql.Data.MySqlClient;` at the top of your source file.
RickNZ
2009-12-17 05:05:04
Thank you very much for response
shashi
2009-12-22 10:43:24