在asp.net中连接MySql、使用MySql.Data.DLL、完全ADO.NET访问模式、操作方便如同SQL Server
MySql.Data.dll下载地址:
using MySql.Data.MySqlClient; public partial class Msg : System.Web.UI.Page { protected void Page_Load( object sender, EventArgs e) { string conn = "Data Source=127.0.0.1;User ID=root;Password=123;DataBase=NewDB;Charset=gb2312;"; MySqlConnection con = new MySqlConnection(conn); con.Open(); MySqlCommand cmd = new MySqlCommand( " select * from book " ,con); MySqlDataReader dr = cmd.ExecuteReader(); GridView1.DataSource = dr; GridView1.DataBind(); dr.Close(); con.Close(); } } 需要说明的是:MySql中的参数化不同于SqlServer Sqlserver的参数化写法: myCommand.Parameters.Add(new SqlParameter("@Address", SqlDbType.NVarChar, 40)); myCommand.Parameters["@Address"].Value = address.Value; MySql的参数化写法: cmd.Parameters.Add(new MySqlParameter("?p_bname", MySqlDbType.VarChar, 50)); cmd.Parameters["?p_bname"].Value = book.Text;