This is a class library written in VB. NET to connect to MySQL. You can use this class library to directly operate MySQL databases.
Before using this class library, you must install
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
There are three classes in this library:
Manipstringformysql: This class modifies the sgbd string
Mysql_requettes: send a request
Mysql_utils: Test sgbd data
The following is an example of using this library to operate MySQL.
Code:
- 'Operate Dataset
- Public shared function mydbcdataset (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
- 'Xxion à 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 mydbcconnexion 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)
- Mydbcconnexion. Close ()
- Return DS
- Catch mydbcexception as odbcexception
- '
- Httpcontext. Current. response. Write (mydbcexception. tostring)
- Catch myexception as exception
- '
- Httpcontext. Current. response. Write (myexception. tostring)
- End try
- End Function
- 'Call the Function
- Dim mondatasettemp as dataset = mysql_requettes.mydbcdataset (
- SQL,
- Constantes. odbcbase,
- Constantes. odbcserver,
- Constantes. odbcpwd,
- Constantes. odbcuser,
- "Mondataset ")
The class library used by this program can be downloaded at the address below: http://www.codeproject.com/dotnet/MySQLConnexion/MySQLConnexion.zip