VB.NET 通过MySQLDriverCS连接Mysql

本文介绍如何使用VB.NET连接MySQL数据库,包括安装MySQLDriverCS、配置连接字符串、执行SQL语句及解决中文乱码问题等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. 通过https://sourceforge.net/projects/mysqldrivercs/下载MySQLDriverCS安装程序,安装到本地电脑上,(后续不需要每台电脑都安装此程序),找到安装位置中的dll文件夹,
  2. 在.net程序中引用上面文件夹中的MySQLDriverCS.dll文件,并在代码中导入,并把 MySQLDriverCS.dll, libmySQL.dll,libmySQL-4.0.dll拷贝到项目文件夹中
Imports MySQLDriverCS
  1. 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.youkuaiyun.com/michaelscofielddong/article/details/7750380

Dim commandm As MySQLCommand = New MySQLCommand("set names gb2312", Connection)
commandm.ExecuteNonQuery()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

huangle63

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值