Implementation Code for connecting Asp.net to MySQL []

Source: Internet
Author: User

MySQL connector/net5.0:
Http://dev.mysql.com/get/Downloads/Connector-Net/mysql-connector-net-5.0.6.zip/from/pick
After installation,
Click properties, then find the target, click a directory to the upper level, and find binaries \. NET 2.0, and then copy this file to your project directory. Generally, such DLL files will be saved to the bin directory.

InCodeEnter using MySQL. Data. mysqlclient in the page; then write mysqlconnection in the page_load function. The prompt is displayed when the word is written in half. Do you need to write the following information? "The Code has been intelligently completed". You can simply write a piece of code and try it. It is similar to sqlserver.
The following two sections of code are provided for reference: one code page
Code under defa2.2.aspx. CS:

C # code
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)
{
Bookres + = mydatareader ["ID"];
Bookres + = mydatareader ["user"];
Bookres + = mydatareader ["pass"];
}
Mydatareader. Close ();
Myconnection. Close ();
Lb1.text = bookres;
}
}

1. Download the MySQL database at: http://www.mysql.com/. the installation is convenient and can be triggered.

2. After MySQL is installed, there is no client tool by default (such as the Enterprise Manager and query Analyzer of sqlserver). It is just a server that stores data. You need to download another client tool for convenience, SQL manager for MySQL is recommended, which is simple, compact, and powerful. Download: http://www.sqlmanager.net/en/products/mysql/manager/download

3. asp. net to connect to MySQL requires a component (. net itself does not provide a driver to access MySQL) MySQL. data. DLL, which is officially provided (pure C # development, Open Source). Multiple versions are available, and the data access mode is ADO. net, which is similar to Asp.net's access to sqlserver and is very simple. Download (there is a demo inside): http://dev.mysql.com/downloads/connector/net/5.1.html

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.