搜索: 标题内容作者  
  首页VB.NET教程VB.NET进阶教程
背景:
阅读新闻

在VB.NET中如何操作MySQL数据库

[日期:2008-07-02]   来源:互联网整理  作者:佚名   [字体: ]
    新闻简介:这是在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 
这是在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")
  
  此程序用到的类库可在如下地址下载:http://www.codeproject.com/dotnet/MySQLConnexion/MySQLConnexion.zip

If you believe an article violates your rights or the rights of others, please contact us.

收藏 推荐 打印 | 录入:admin | 阅读:
相关新闻      
友情链接
本文评论   [发表评论] 全部评论 (0)
赞助商广告
热门评论