VB.NET 通过MySQLDriverCS连接Mysql

  1. 通过https://sourceforge.net/projects/mysqldrivercs/下载MysqLDriverCS安装程序,安装到本地电脑上,(后续不需要每台电脑都安装此程序),找到安装位置中的dll文件夹,
  2. 在.net程序中引用上面文件夹中的MysqLDriverCS.dll文件,并在代码中导入,并把 MysqLDriverCS.dll, libMysqL.dll,libMysqL-4.0.dll拷贝到项目文件夹中
Imports MysqLDriverCS
    3.
Try
    Dim MysqL As String = "Location=10.*.*.*;User Id=root;Data Source=;Port=3306;Password="
    'Dim MysqL As String = "server=localhost;User Id=root;Data Source=;Port=3306;Password="
    Dim Connection As New MysqLConnection(MysqL)
    Connection.open()   '打开数据库
    Dim sql As String = "insert into technologydept_onlinemackey set mainboardID='123456',test_time=Now()"
    Dim command As MysqLCommand = New MysqLCommand(sql,Connection)
    'Dim mydata As MysqLDataReader
    'mydata = command.ExecuteReaderEx
    'While mydata.Read
    ' If mydata.HasRows Then
    ' MsgBox(mydata(0).ToString)
    ' Else
    ' MsgBox("no")
    ' End If
    'End While
    command.ExecuteNonQuery()
    command.dispose()
    Connection.Close()
    MsgBox("OK")
Catch ex As Exception
    MsgBox(ex.Message)
End Try

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...