这是Els to mdb 的,你只修改 mCnnStringA 为SQL 连接就可以了 ----------------------------------------------------------- Option Explicit Public mCnnStringE As String Public mCnnStringA As StringPrivate Sub Form_Load() mCnnStringE = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source= " & App.Path & "\Book1.xls;" & "Extended Properties=""Excel 8.0;HDR=Yes;"";" mCnnStringA = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb" & ";Persist Security Info=False" End SubPrivate Sub Command1_Click() Dim mConE As New ADODB.Connection Dim mRstE As New ADODB.Recordset Dim mConA As New ADODB.Connection Dim mRstA As New ADODB.Recordset Dim i As Integer mConE.Open mCnnStringE mConA.Open mCnnStringA mRstE.CursorLocation = adUseClient mRstA.CursorLocation = adUseClient mRstE.Open "Select * From [Sheet1$] Where mDate Between #" & "2003-12-11#" & "And #" & "2010-12-11#", mCnnStringE, adOpenStatic, adLockOptimistic mRstA.Open "Select * From mTable Where 1 = 0", mCnnStringA, adOpenStatic, adLockOptimistic Do Until mRstE.EOF mRstA.AddNew For i = 0 To mRstE.Fields.Count - 1 mRstA.Fields.Item(i).Value = mRstE.Fields.Item(i).Value Next i mRstE.MoveNext Loop mRstA.Update Set mRstE = Nothing Set mConE = Nothing Set mRstA = Nothing Set mConA = Nothing End Sub
-----------------------------------------------------------
Option Explicit
Public mCnnStringE As String
Public mCnnStringA As StringPrivate Sub Form_Load()
mCnnStringE = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source= " & App.Path & "\Book1.xls;" & "Extended Properties=""Excel 8.0;HDR=Yes;"";"
mCnnStringA = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb" & ";Persist Security Info=False"
End SubPrivate Sub Command1_Click()
Dim mConE As New ADODB.Connection
Dim mRstE As New ADODB.Recordset
Dim mConA As New ADODB.Connection
Dim mRstA As New ADODB.Recordset
Dim i As Integer
mConE.Open mCnnStringE
mConA.Open mCnnStringA
mRstE.CursorLocation = adUseClient
mRstA.CursorLocation = adUseClient
mRstE.Open "Select * From [Sheet1$] Where mDate Between #" & "2003-12-11#" & "And #" & "2010-12-11#", mCnnStringE, adOpenStatic, adLockOptimistic
mRstA.Open "Select * From mTable Where 1 = 0", mCnnStringA, adOpenStatic, adLockOptimistic
Do Until mRstE.EOF
mRstA.AddNew
For i = 0 To mRstE.Fields.Count - 1
mRstA.Fields.Item(i).Value = mRstE.Fields.Item(i).Value
Next i
mRstE.MoveNext
Loop
mRstA.Update
Set mRstE = Nothing
Set mConE = Nothing
Set mRstA = Nothing
Set mConA = Nothing
End Sub