ASP.NET source codes for accessing the MySQL database

Here is an example of ASP.NET (Visual Basic) code:

<%

   Dim cn As System.Data.Odbc.OdbcConnection = Nothing
   Dim cmd As System.Data.Odbc.OdbcCommand = Nothing
   Dim dr As System.Data.Odbc.OdbcDataReader = Nothing


   ' Replace the values of the server, database, uid and pwd fields in the following connection string
   ' with the respective values on your control panel: server, database, username, password
   Dim ConnectionString As String = "driver={MySQL ODBC 3.51 Driver};" & _
   "server=127.0.0.1;database=m1d1;uid=m1d1;pwd=ehd71a9soduv62sw;"


   ' Establish a connection with the server
   cn = New System.Data.Odbc.OdbcConnection(ConnectionString)
   cn.Open()


   ' Read all the names in the user table
   cmd = New System.Data.Odbc.OdbcCommand("SELECT name FROM users", cn)
   dr = cmd.ExecuteReader()


   ' Write all the names in the user table
   While dr.Read()
      Response.Write(dr("name") & "<br />")
   End While


   ' Mostly importantly, close the data reader and connection correctly
   dr.Close() ' closes the data reader
   cn.Close() ' closes the connection

%>

back