微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

原文地址:https://www.jb51.cc/vb/256624.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐