這是在VB.Net中為連接MySql中編寫的一個類庫。你可以使用這個類庫直接操作MySQL數據庫。
在使用這個類庫之前,你必須安裝
ODBC MYSQL 3.51下載地址:http://www.MySQL.com/downloads/api-myodbc-3.51.Html
Driver ODBC.Net下載地址:http://www.microsoft.com/downloads/details.ASPx?FamilyId=6CCD8427-1017-4F33-A062-D165078E32B1&displaylang=en
在這個庫中有三個類:
ManipStringForMySQL: 此類修改SGBD的字符串
MySQL_Requettes: 發送請求
MySQL_Utils : 對SGBD數據進行測試
下面是使用此類庫操作MySQL的一個例子
//對DataSet進行操作
Public Shared Function MyODBCDataset(ByVal ReqSQL As String, _
ByVal LaBase As String, ByVal Server As String, _
ByVal PassWord As String, ByVal User As String, _
ByVal NomDataSet As String) As DataSet
' Connexion à un server MySQL
'avec le Driver ODBC 3.51 avec requette qui renvoIE un dataset
Dim MyConString As String = _
"DRIVER={MySQL ODBC 3.51 Driver};SERVER=" & Server _
& ";DATABASE=" & LaBase & ";UID=" & User _
& ";PASSWORD=" & PassWord & ";OPTION=3;"
Dim MyODBCConnexion As New OdbcConnection(MyConString)
Try
Dim ds As New DataSet()
Dim cmd As OdbcDataAdapter = New
OdbcDataAdapter(ReqSQL, MyConString)
Dim MyCommand As New OdbcCommand()
Dim MyDataReader As OdbcDataReader
cmd.Fill(ds, NomDataSet)
MyODBCConnexion.Close()
Return ds
Catch MyOdbcException As OdbcException
'
HttpContext.Current.Response.Write(MyOdbcException.ToString)
Catch MyException As Exception
'
HttpContext.Current.Response.Write(MyException.ToString)
End Try
End Function
//對函數的調用
Dim MonDatasetTemp As DataSet = MySQL_Requettes.MyODBCDataset(
SQL,
constantes.ODBCBase,
constantes.ODBCServer,
constantes.ODBCPwd,
constantes.ODBCUser,
"MonDataset")
此程序用到的類庫可在如下地址下載:點擊下載