1、定義連接db的過(guò)程:Dim oConn As ADODB.ConnectionPrivate Sub ConnectDB() Set oConn = New ADODB.Connection oConn.Open "DRIVER={mysql ODBC 5.1 Driver};" & _ "SERVER=localhost;" & _ "DATABASE=yourdatabase;" & _ "USER=yourdbusername;" & _ "PASSWORD=yourdbpassword;" & _ "Option=3"End Sub2、執(zhí)行db插入的具體寫法:Dim rs As ADODB.RecordsetPrivate Sub InsertData() Set rs = New ADODB.Recordset ConnectDB With wsBooks For rowCursor = 2 To 11 strSQL = "INSERT INTO tutorial (author, title, price) " & _ "VALUES ('" & esc(.Cells(rowCursor, 1)) & "', " & _ "'" & esc(.Cells(rowCursor, 2)) & "', " & _ esc(.Cells(rowCursor, 3)) & ")" rs.Open strSQL, oConn, adOpenDynamic, adLockOptimistic Next End WithEnd Sub
網(wǎng)站導(dǎo)航
- zblogPHP模板zbpkf
- zblog免費(fèi)模板zblogfree
- zblog模板學(xué)習(xí)zblogxuexi
- zblogPHP仿站zbpfang
mysql的with查詢,vba怎么將excel數(shù)據(jù)插入mysql數(shù)庫(kù)庫(kù)?
下一篇intp的十大特征