ASP. NET connection to MySQL database (using MySql.Data.dll)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.