|
本帖最后由 jin1379 于 2022-12-15 12:18 编辑
附件的代码是能正常写入数据到mysql的,问题是每一条去写入太慢了,7万行写入差不多要半小时左右,请问各位大神还有没有更好的方法?谢谢!
每写入一条数据差不多要1秒
- Sub order()
- Dim strConn As String, strSQL As String
- Dim conn As ADODB.Connection
- Dim rs As ADODB.Recordset
- arr = Range("a2:e" & Range("a1").End(xlDown).Row)
- For i = 3 To UBound(arr)
- Set conn = New ADODB.Connection
- Set rs = New ADODB.Recordset
- strConn = "Driver={MySQL ODBC 8.0 Unicode Driver};Server=172.20.63.136;DB=jsw;UID=root;PWD=123456;OPTION=3;"
- strSQL = "insert into supplier_inventory_record value('" & arr(i, 4) & "','" & arr(i, 1) & "','" & arr(i, 2) & "','" & arr(i, 3) & "' ,'" & arr(i, 5) & "','" & Format(Now, "yyyy-mm-dd hh:mm:ss") & "'); "
- conn.Open strConn
- rs.Open strSQL, conn
- Set rs = Nothing
- conn.Close
- Set conn = Nothing
- Next
- End Sub
复制代码
|
|