MySQL的connector/net5.0下載地址:
http://dev.mysql.com/get/Downloads/Connector-Net/MySQL-connector-net-5.0.6.zip/from/pick安裝好以後,
點屬性,然後點查找目標,點向上一層目錄,找到BinarIEs\.Net 2.0,然後將這個文件復制到你的工程目錄下,一般這樣的DLL文件會保存到bin目錄下.
在代碼頁裡輸入using Mysql.Data.MysqlClIEnt;然後再在Page_Load函數裡寫MySQLConnection,在單詞寫到一半時提示就出來了,下面的就不用寫了吧?都已經出現”代碼智能完成了”,隨便寫一段代碼試試就可以了,和Sqlserver完全相似.
下面提供兩段代碼供參考,一個代碼頁,一個是Html頁:
default2.ASPx.cs下的代碼:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data.MySQLClIEnt;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string query = "select * from guestbook";
MySqlConnection myConnection = new MySQLConnection("server=localhost;user id=root;passWord=;database=guestbook");
MySqlCommand myCommand=new MySQLCommand(query,myConnection);
myConnection.Open();
myCommand.ExecuteNonQuery();
MySQLDataReader myDataReader = myCommand.ExecuteReader();
string bookres="";
while (myDataReader.Read()==true)
{