Asp.net and mysql database connection method and instance code

Source: Internet
Author: User
Tags mysql tutorial mysql odbc driver

Asp tutorial. net tutorial and mysql tutorial database tutorial connection method and instance code

MySQL database is a low-cost MySQL SQL Server database, and can
Easy-to-use network applications, including ASP. NET projects. Connect to MySQL from ASP. NET. We will use ODBC
Connect to our MySQL database. NET data provider and DSN connection.

. Make sure that you have installed it on your server. Net Framework

. Download ODBC. . NET data provider and installed on your server. You can
Download it here:
Http://www.microsoft.com/downloads/release.asp? ReleaseID = 35715

. Make sure that the Microsoft. Data. ODBC. dll program file is located in the following folder:
In your server C: Program Files file Microsoft. NET Odbc. Net.

. Install Microsoft Data Access Component (MDAC) 2.6 or later. In MDAC 2.8
Recommended. You can download here: http://msdn.microsoft.com/data/

. Install the MySQL server.

. Install the MySQL ODBC driver, 3.51 of MyODBC. You can download it here:
Http://www.mysql.com/downloads/api-myodbc-3.51.html

The following is the actual code connecting to the MySQL database and retrieval and
All records in your database are displayed in table 1.

<% @ Page CompilerOptions = '/R: "C: Program FilesMicrosoft. NETOdbc. NetMicrosoft. data. odbc. dll"' %>
<% @ Import Namespace = "System. Data" %>
<% @ Import Namespace = "Microsoft. Data. Odbc" %>
<HTML>
<HEAD>
<SCRIPT Language = "VB" Runat = "server">
Sub Page_Load (Source as object, e as EventArgs)
Dim sConString As String = "DRIVER ={ MySQL ODBC 3.51 Driver}; SERVER = localhost;
DATABASE = Your_Mysql_DB; UID = mysql_username; PASSWORD = mysql_password; OPTION = 3"
Dim oConnection as ODBCConnection = new ODBCConnection (sConString)
Dim sSQL as String = "SELECT * FROM Table1"
Dim oDataAdapter as ODBCDataAdapter = New ODBCDataAdapter (sSQL, oConnection)
Dim oDataSet as DataSet = new DataSet ()
ODataAdapter. Fill (oDataSet)
ODataGrid. DataSource = oDataSet
ODataGrid. DataBind ()
End Sub
</SCRIPT>
</HEAD>
<BODY>
<ASP: DataGrid ID = "oDataGrid" Runat = "server"/>
</BODY>
</HTML>.

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.