Chinaunix首页 | 论坛 | 博客
  • 博客访问: 90344186
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类: Mysql/postgreSQL

2008-03-28 10:22:55

来源:ccidnet.com    作者:korn

这是在VB.net中为连接MySQL中编写的一个类库。你可以使用这个类库直接操作MySql数据库。

  在使用这个类库之前,你必须安装
  ODBC MYSQL 3.51下载地址:
  Driver ODBC.NET下载地址:

  在这个库中有三个类:
  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")

阅读(712) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~