The previous use of ASP. NET Web site use is SQL Server database, and do not know how to connect with MySQL, then today tried, needless to say, directly on the steps.
First I use MySql.Data.dll this way to connect the database, I put on the Baidu cloud, you can download: http://pan.baidu.com/s/1o78bql0
MySQL installation I'm not going to say much, fool. Installation is possible, here a visualization tool is recommended
You can easily see the tables in the database: For a simple test, I put a field in the Database LL table. Date
Next, in the ASP. NET project, right-click the Add MySql.Data.dll reference, such as:
After adding the reference, we'll see the reference below the bin,
To this step the configuration is done, next test:
Add the GridView space to the page and enter it in CS:
protected voidPage_Load (Objectsender, EventArgs e) { stringconn ="Data source=127.0.0.1; User Id=root; PASSWORD=ROOT;DATABASE=LP"; Mysqlconnection Con=Newmysqlconnection (conn); Con. Open (); Mysqlcommand cmd=NewMysqlcommand ("SELECT * FROM LL", con); Mysqldatareader Dr=cmd. ExecuteReader (); Gridview1.datasource=Dr; Gridview1.databind (); Dr. Close (); Con. Close (); }
Final effect:
ASP. NET connection to MySQL database (using MySql.Data.dll)