VB.NET 通过MySQLDriverCS连接Mysql

前端之家收集整理的这篇文章主要介绍了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

猜你在找的VB相关文章