
《MySQL 8.0.17》百度网盘资源免费下载:
链接: https://pan.baidu.com/s/1PQdVY20q0er1aX7mgxu-QQ
?pwd=988a 提取码: 988aMySQL 8.0.17是一种开放源代码的关系型数据库管理系统,使用最常用的数据库管理语言–结构化查询语言SQL进行数据库管理。MySQL 8.0.17优化了SQL查询算法,有效地提高查询速度;支持多线程,充分利用CPU资源,支持多用户;提供用于管理、检查、优化数据库 *** 作的管理工具。由于其体积小、速度快、总体拥有成本低,目前被广泛地应用在Internet上的中小型网站中。
由于ADO对象不直接支持MySQL,所以必须先安装MyODBC, 后者也是一个免费产品,在 www.mysql.org上有下载,安装好了MyODBC, 就可以在ODBC数据源管理中配置一个数据源名称,把它指向你想连接的MySQL数据库。代码如下:Sub connectMySQL() '通过MyODBC去连接MySQL数据库,并将Microsoft SQL Server 7 '的数据转进mysql中 Dim sConnect As String, sSql As String, i As Long Dim cnMSSQL As New ADODB.Connection Dim cnMySQL As New ADODB.Connection'声明并创建对象 连接 Dim rs As New ADODB.Recordset '声明并创建对象 记录集 Dim cm As New ADODB.Command '声明并创建对象 命令sConnect = "dsn=mysql1" '指定MySQL的数据源名称 cnMySQL.Open sConnect '连接到 mysqlsConnect="Provider=SQLOLEDB.1Persist Security Info=FalseUser ID=sapwd=123456Initial Catalog=softdownData Source=ntserver" '连接到 ms sql server 7 cnMSSQL.Open sConnect'sSql = "create table softinfo (softNum smallint,softname varchar(70),softdesc blob," &_ "softpath varchar(30),softleng varchar(10),softclass varchar(10),softsugest tinyint(1)," &_ "softdown smallint(4))" '创建新的MySQL数据表语句 sSql = "select * from softinfo order by softnum" rs.Open sSql, cnMSSQL, 1, 1 While Not rs.EOF sSql = "insert into softinfo values (" &Trim(rs(0).Value) &",'" &Trim(rs(1).Value) &_"','" &Trim(rs(2).Value) &"','" &Trim(rs(3).Value) &"','" &Trim(rs(4).Value) &_"','" &Trim(rs(5).Value) &"'," &Trim(rs(6).Value) &"," &Trim(rs(7).Value) &")" cm.ActiveConnection = cnMySQL cm.CommandType = adCmdText cm.CommandText = sSql cm.Execute rs.MoveNext Wendrs.Close Set rs = NothingcnMySQL.Close Set cnMySQL = NothingcnMSSQL.Close Set cnMSSQL = Nothing End Sub首先你本地要安装MySQL Connector Net
工程引用mysql.data
连接数据库:
Imports MySql.Data
Imports MySql.Data.MySqlClient
‘连接字符串dbServerName 是ip,下面的英文应该懂得吧。
dim sA as string
sA = "server=" &Me.dbServerName &"port=3306database=" &Me.dbDataBaseName &_
"user id=" &Me.dbUserName &"password=" &Me.dbPassWord &""
dim mvardbConnectionMysql As MySqlConnection
With mvardbConnectionMysql
.ConnectionString = sA
.Open()
End With
4. 读取数据
dim xx As MySqlDataReader
Dim oC As MySqlCommand = New MySqlCommand(sSql, Me.mvardbConnectionMysql)
oC.CommandType = CommandType.Text
xx= oC.ExecuteReader()
if xx.HasRows
do while xx.read() ’一次读取一行
msgbox xx.item(2) '取出当前行的第三个字段的值显示。
loop
end if
5. 写入数据
Dim oT As MySqlTransaction = Me.mvardbConnectionMysql.BeginTransaction()
Try
Dim oC As MySqlCommand
'下面的commandtext是执行的更新语句,例如Insert into 语句。
oC = New MySqlCommand(CommandText, Me.mvardbConnectionMysql, oT)
oC.CommandType = CommandType.Text
oC.ExecuteNonQuery()
oT.Commit()
oC = Nothing
oT = Nothing
Catch oe As Exception
oT.Rollback()
End Try
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)