VB.NET 通过MySQLDriverCS连接Mysql

来源:互联网 发布:淘宝匿名购买好不好 编辑:程序博客网 时间:2024/06/05 09:16
  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 commandm As MySQLCommand = New MySQLCommand("set names gb2312", Connection)    commandm.ExecuteNonQuery()    commandm.Dispose()    '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.net 与mysql通信中文产生乱码的问题
http://blog.csdn.net/michaelscofielddong/article/details/7750380

Dim commandm As MySQLCommand = New MySQLCommand("set names gb2312", Connection)commandm.ExecuteNonQuery()
原创粉丝点击