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>.