. NET writing class library direct operation MySQL database application example

Source: Internet
Author: User
Tags httpcontext odbc tostring mysql database

This is a library of classes written in vb.net for connecting to MySQL. You can use this class library to manipulate the MySQL database directly.

Before using this class library, you must install the

ODBC MYSQL 3.51 Download Address: http://www.mysql.com/downloads/api-myodbc-3.51.html

Driver ODBC. NET download address: 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 Request

Mysql_utils: Test the SGBD data

Here is an example of using this class library to manipulate MySQL

Manipulating a DataSet

Public Shared Function Myodbcdataset (ByVal reqsql as String, _
         ByVal labase As String, ByVal Server As String, _
         ByVal Password as S Tring, 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 = _
        "D River={mysql ODBC 3.51 Driver}; Server= "& Server _
        &";D atabase= "& 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

Call to a function

Dim mondatasettemp as DataSet = Mysql_requettes.myodbcdataset (
Sql
Constantes. Odbcbase,
Constantes. Odbcserver,
Constantes. Odbcpwd,
Constantes. Odbcuser,
"Mondataset")

The class library used by this program can be downloaded at the following address: Http://www.codeproject.com/dotnet/MySQLConnexion/MySQLConnexion.zip

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.