|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
以下示例为将access中的table1表追加到sql server中的server_table表中,程序在access vba中通过
Dim ConnAcc As New ADODB.Connection
Dim RsAcc As New ADODB.Recordset
Dim ConnSql As New ADODB.Connection
Dim RsSql As New ADODB.Recordset
ConnAcc.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\mdbname;Persist Security Info=False"
ConnSql.ConnectionString = "Provider=SQLOLEDB.1;Password=pwd;Persist Security Info=True;User ID=domain_chj;Initial Catalog=newstardbase;Data Source=servername"
ConnAcc.Open
RsAcc.CursorLocation = adUseClient
RsAcc.Open "table1", ConnAcc, adOpenStatic, adLockBatchOptimistic
If RsAcc.EOF Then MsgBox "无数据,程序将退出...": End
RsAcc.MoveFirst
ConnSql.Open
Do While Not (RsAcc.EOF)
ConnSql.Execute "insert into server_table values('" & RsAcc.Fields(0) & "','" & RsAcc.Fields(1) & "','" & RsAcc.Fields(2) & "','" & RsAcc.Fields(3) & "','" & RsAcc.Fields(4) & "')"
Loop |
|