vb中复制数据库的一条记录到另一个相同的数据库中(access文件)
展开全部
使用2个数据连接,
全部打开,按条插入
如:dim conn1 as adodb.connection, conn2 as adodb.connection
dim sqlstr as string
sqlstr = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=456123;Data Source=" & App.Path & "\DB.mdb;Persist Security Info=True"
Set conn1 = New ADODB.Connection
conn1.CursorLocation = adUseClient
conn1.Open sqlstr
sqlstr = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=456123;Data Source=" & App.Path & "\DB1.mdb;Persist Security Info=True"
Set conn2 = New ADODB.Connection
conn2.CursorLocation = adUseClient
conn2.Open sqlstr
dim rs as adodb.recordset
dim i as integer, fieldCount as integer
set rs = conn1.execute("select * from table1")
if rs.eof then exit sub
fieldCount = rs.Fields.Count
do while rs.eof = false
sqlstr = "insert into table1 values('"
for i = 0 to fieldCount - 2
sqlstr = sqlstr & rs.fields(i) & "','"
next i
sqlstr = sqlstr & rs.fields(i) & "')"
conn2.execute(sqlstr)
rs.movenext
loop
rs.close
conn1.close
conn2.close
全部打开,按条插入
如:dim conn1 as adodb.connection, conn2 as adodb.connection
dim sqlstr as string
sqlstr = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=456123;Data Source=" & App.Path & "\DB.mdb;Persist Security Info=True"
Set conn1 = New ADODB.Connection
conn1.CursorLocation = adUseClient
conn1.Open sqlstr
sqlstr = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=456123;Data Source=" & App.Path & "\DB1.mdb;Persist Security Info=True"
Set conn2 = New ADODB.Connection
conn2.CursorLocation = adUseClient
conn2.Open sqlstr
dim rs as adodb.recordset
dim i as integer, fieldCount as integer
set rs = conn1.execute("select * from table1")
if rs.eof then exit sub
fieldCount = rs.Fields.Count
do while rs.eof = false
sqlstr = "insert into table1 values('"
for i = 0 to fieldCount - 2
sqlstr = sqlstr & rs.fields(i) & "','"
next i
sqlstr = sqlstr & rs.fields(i) & "')"
conn2.execute(sqlstr)
rs.movenext
loop
rs.close
conn1.close
conn2.close
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
利用Dataset的Copy方法即可。
先获取一个表的数据到DataSet中,查询另一个表中的信息到NewDataset中,
NewDataset = dataset.copy
最后用DataAdapter更新一下NewDataset 就好了。
先获取一个表的数据到DataSet中,查询另一个表中的信息到NewDataset中,
NewDataset = dataset.copy
最后用DataAdapter更新一下NewDataset 就好了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
打开二个库的相同的表,按条插入就行了呀。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
for i=1to3
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询