mySql With Asp.Net
by
Imran
16/April/2008
|
 |
Here is an example for mySQL with Asp.NetFirst Step to connect with mySql you should download mysql Driver from following links
http://dev.mysql.com/downloads/connector/odbc/3.51.html
http://dev.mysql.com/get/Downloads/Connector-ODBC/3.51/ mysql-connector-odbc-3.51.24-win32.msi/from/pick?done=ef2959aa46636b
Then right code same like
Imports System.Data Imports System.Data.Odbc
Partial Class test2 Inherits System.Web.UI.Page Dim myconstr2 = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=server; DATABASE=yourdb;USER=dbuser;PASSWORD=dbpassword; OPTION=3;"
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim sql As String = "select * from table" Dim ds As New DataSet ds = FillDS(sql) Response.Write(ds.Tables(0).Rows.Count) End Sub
Private Function FillDS(ByVal sql As String) As DataSet Dim con As New OdbcConnection(myconstr2) Dim da As New OdbcDataAdapter(sql, con) Dim ds As New DataSet da.Fill(ds) con.Close() Return ds End Function End Class
|
|
|