Home » Categories » Multiple Categories

How do I query MySQL database in ASP.NET?

In order to query your mySQL Database with ASP.NET script, you need to organize an ODBC connection with us first. The following the snippet of the code:

<%@ Page Language="VB" %>
<%@ import Namespace="System.Data.Odbc" %>

<script runat="server">

Public Sub Page_Load()
     Dim mySelectQuery As String = "SELECT * FROM tblTest"
     Dim myConnection As New OdbcConnection("DSN=<username>_mysqlConn")

     Dim myCommand As New OdbcCommand(mySelectQuery, myConnection)
     Dim myReader As OdbcDataReader = myCommand.ExecuteReader()
          While myReader.Read()
          Response.Write (myReader("name") & "<br>")
     End While
          //always call Close when done reading.
          //always call Close when done with connection.
     End Try
End Sub


Attachments Attachments
There are no attachments for this article.
Related Articles RSS Feed
Do you support Remote MSSQL connection?
Viewed 3171 times since Mon, Apr 30, 2012
About Azure Key Vault
Viewed 594 times since Mon, Nov 2, 2020
How do I send an email from my ASP.NET website by using SMTP Authentication?
Viewed 5702 times since Tue, May 1, 2012
Do you support MySQL WebAdmin Access?
Viewed 2550 times since Tue, May 1, 2012
Sample Code to Send email using ASP.NET 2
Viewed 4960 times since Tue, May 1, 2012
Do you support Remote mySQL connection?
Viewed 2643 times since Mon, Apr 30, 2012
What is the connection string for my mariaDB database?
Viewed 762 times since Fri, Jun 26, 2020
How often do you backup my website?
Viewed 4016 times since Tue, May 1, 2012