asp.net connection MySQL implementation code []_ Practical Tips

Source: Internet
Author: User
MySQL's connector/net5.0 download address:
Http://dev.mysql.com/get/Downloads/Connector-Net/mysql-connector-net-5.0.6.zip/from/pick
After the installation is ready,
Point property, then point to find the target, point up a directory, find Binaries\.net 2.0, and then copy the file to your engineering directory, typically such DLL files will be saved to the bin directory.

Enter a using Mysql.Data.MysqlClient in the code page, and then write the mysqlconnection in the Page_Load function, when the word is written in half, the hint comes out, the following is not to write it? "code intelligence is complete," Just write a piece of code and try it, exactly like SQL Server.
Here are two pieces of code for your reference, a code page
Code under Default2.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=;d atabase=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, address: http://www.mysql.com/, the size of only dozens of trillion only, installation is very convenient, then the hint can be.

2, MySQL installed by default is not a client tool (like SQL Server Enterprise Manager, Query Analyzer, etc.), just a server to store data, in order to facilitate you to download a client tool, there are many, recommend the use of SQL Manager for MySQL, simple and compact, function is also strong. Download: http://www.sqlmanager.net/en/products/mysql/manager/download

3, ASP. NET connection MySQL requires a component (. NET itself does not provide access to MySQL driver) MySQL.Data.Dll, which is officially available (pure C # development, open source OH), has multiple versions to choose from, The data access pattern used is ado.net, very similar to asp.net access to SQL Server, 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.