Connecting ASP.NET and MySQL






1.86/5 (4 votes)
Jan 30, 2007

24362
Connecting ASP.NET and MySQL
Introduction
This article demonstrates the connection between between ASP.NET and MySQL.
Code
Imports System.Data
Imports System.Data.Odbc
Partial Class connstring
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ConnStr As String = "Server=serverip;Provider=MySQLProv;Driver={MySQL ODBC 3.51 Driver};Database=databasename;uid=username;pwd=password"
Dim conn As New Odbc.OdbcConnection(ConnStr)
Dim olecmd As New Odbc.OdbcCommand("select * from Activity", conn)
Dim reader As Odbc.OdbcDataReader
conn.Open()
reader = olecmd.ExecuteReader
reader.Read()
While reader.Read
Response.Write(reader("Name") & "<br>")
End While
End Sub
End Class