|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
这个代码是原来用的,原来没发生过这种情况,新电脑拿来安装最新版本的MySQL和odbc以后,插入速度贼慢,请高人指点迷津
代码的目的是吧Excel表中的内容更新到MySQL中
Sub 订单()
Sheets("订单").Select
Dim strconnt As String
strconnt = ""
Set connt = New ADODB.Connection
Dim rs As Object
Set rs = New ADODB.Recordset
Dim sevip, Db, user, pwd As String
sevip = "localhost"
Db = "jsg"
user = "root"
pwd = "123456"
strconnt = "DRIVER={MySQL ODBC 8.0 Unicode Driver};SERVER=" & sevip & ";Database=" & Db & ";Uid=" & user & ";Pwd=" & pwd & ";Stmt=set names GBK" '
connt.ConnectionString = strconnt
connt.Open '链接sql
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastRow
Sql = "insert into `订单`(`营业日期` ,`支付时间` ,`订单号` ,`订单状态` ,`门店名称` ,`订单来源` ,`就餐人数` ,`顾客姓名` ,`顾客电话` ,`顾客性别` ,`配送地址` ,`商品总额` ,`商户实收` ,`优惠金额` ,`现金` ,`微信` ,`支付宝` ,`团购` ,`外卖`)values('" & Cells(i, 1) & "','" & Cells(i, 2) & "','" & Cells(i, 3) & "','" & Cells(i, 4) & "','" & Cells(i, 5) & "','" & Cells(i, 6) & "','" & Cells(i, 7) & "','" & Cells(i, 8) & "','" & Cells(i, 9) & "','" & Cells(i, 10) & "','" & Cells(i, 11) & "','" & Cells(i, 12) & "','" & Cells(i, 13) & "','" & Cells(i, 14) & "','" & Cells(i, 15) & "','" & Cells(i, 16) & "','" & Cells(i, 17) & "','" & Cells(i, 18) & "','" & Cells(i, 19) & "')"
connt.Execute Sql
Next
connt.Close
Set connt = Nothing
MsgBox "保存成功!"
Exit Sub
End Sub
|
|