在线
客服

在线客服
尊敬的客户,我们24小时竭诚为您服务 公司总机: 0755-83312037 (32条线)

客服
热线

0755-83312037 (32条线)
7*24小时客服服务热线

?

关注
微信

关注官方微信
TOP

返回
顶部

在VB.net中连接MySql的类库

发布时间:2019-04-13浏览次数:1012 <p> </p> <table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0"><tbody><tr> <td style="WORD-WRAP: break-word" bgcolor="#fdfddf"> <font color="#ff0000">WebjxCom提示:</font><font color="#000000">.Net编写类库直接操作MySql数据库应用实例.</font> </td> </tr></tbody></table> <p>这是在VB.net中为连接MySql中编写的一个类库。你可以使用这个类库直接操作MySql数据库。 </p> <p>在使用这个类库之前,你必须安装 </p> <p>ODBC MYSQL 3.51下载地址:http://www.mysql.com/downloads/api-myodbc-3.51.html </p> <p>Driver ODBC.NET下载地址:http://www.microsoft.com/downloads/details.aspx?FamilyId=6CCD8427-1017-4F33-A062-D165078E32B1&amp;displaylang=en </p> <p>在这个库中有三个类: </p> <p>ManipStringForMySQL: 此类修改SGBD的字符串 </p> <p>MySQL_Requettes: 发送请求 </p> <p>MySQL_Utils : 对SGBD数据进行测试 </p> <p>下面是使用此类库操作MySql的一个例子 </p> <p>//对DataSet进行操作 </p> <p> </p> <table style="BORDER-BOTTOM: #0099cc 1px solid; BORDER-LEFT: #0099cc 1px solid; TABLE-LAYOUT: fixed; BORDER-TOP: #0099cc 1px solid; BORDER-RIGHT: #0099cc 1px solid" border="0" cellspacing="0" cellpadding="6" width="95%" align="center"><tbody><tr> <td style="WORD-WRAP: break-word" bgcolor="#ddedfb"> <p>  Public Shared Function MyODBCDataset(ByVal ReqSQL As String, _<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ByVal LaBase As String, ByVal Server As String, _<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ByVal Password As String, ByVal User As String, _<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ByVal NomDataSet As String) As DataSet<br>&#160;&#160;&#160; ' Connexion à un server MySQL <br>&#160;&#160;&#160; 'avec le Driver ODBC 3.51 avec requette qui renvoie un dataset<br>&#160;&#160;&#160; Dim MyConString As String = _<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160; "DRIVER={MySQL ODBC 3.51 Driver};SERVER=" &amp; Server _<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &amp; ";DATABASE=" &amp; LaBase &amp; ";UID=" &amp; User _<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &amp; ";PASSWORD=" &amp; Password &amp; ";OPTION=3;"</p> <p>Dim MyODBCConnexion As New OdbcConnection(MyConString)<br>&#160;&#160;&#160; Try<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Dim ds As New DataSet()<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Dim cmd As OdbcDataAdapter = New <br>&#160;&#160;&#160;&#160;&#160;&#160;&#160; OdbcDataAdapter(ReqSQL, MyConString)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Dim MyCommand As New OdbcCommand()<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Dim MyDataReader As OdbcDataReader<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160; cmd.Fill(ds, NomDataSet)<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160; MyODBCConnexion.Close()<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Return ds<br>&#160;&#160;&#160; Catch MyOdbcException As OdbcException<br>&#160;&#160;&#160; ' <br>&#160;&#160;&#160;&#160;&#160; HttpContext.Current.Response.Write(MyOdbcException.ToString)<br>&#160;&#160;&#160; Catch MyException As Exception<br>&#160;&#160;&#160; ' <br>&#160;&#160;&#160;&#160;&#160; HttpContext.Current.Response.Write(MyException.ToString)<br>&#160;&#160;&#160; End Try<br>End Function</p> <p>&#160;&#160;&#160; //对函数的调用</p> <p>&#160; Dim MonDatasetTemp As DataSet = MySQL_Requettes.MyODBCDataset(<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SQL,<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; constantes.ODBCBase, <br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; constantes.ODBCServer, <br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; constantes.ODBCPwd, <br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; constantes.ODBCUser, <br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; "MonDataset")</p> </td> </tr></tbody></table> <p>此程序用到的类库可在如下地址下载:http://www.codeproject.com/dotnet/MySQLConnexion/MySQLConnexion.zip</p>