VB如何同时在一句代码里面同时操作2个数据库.

dxlz 2010-09-26 02:58:31
我的代码如下
Dim db As New ADODB.Connection
Dim db1 As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset
db.ConnectionString = "provider=microsoft.jet.oledb.4.0; " & "data source= " & App.Path & "\send.mdb "
db.Open
db.Execute "UPDATE send SET send1 = '" & Trim(Text1.Text) & "'"
db1.ConnectionString = "provider=microsoft.jet.oledb.4.0; " & "data source= " & App.Path & "\send2.mdb "
db1.Open
db1.Execute "insert into send (send1, send2, send3, send4, send5, send6) SELECT send1, send2, send3, send4, send5, send7 FROM send1"

我想db1.Execute "insert into send (send1, send2, send3, send4, send5, send6) SELECT send1, send2, send3, send4, send5, send7 FROM send1"这里把SEND数据库里的数据写到SEND2数据库里面怎么改?如何操作两个数据里面的表.
...全文
42 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
dxlz 2010-09-26
你们的都可以谢谢.jhone99的更简单些.
回复
Kill2010 2010-09-26
一般人我不告诉他
Private Sub Command1_Click()
Dim Cn1 As New ADODB.Connection
' 声明一个新的连接
Dim Cn2 As New ADODB.Connection
' 声明一个新的连接
Dim Rst2 As New ADODB.Recordset
' 声明一个新的记录集
Dim TableExist As Boolean
' 声明一个布尔型变量,用以区分表是否存在
TableExist = False
'设置初始值
Cn1.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb;Mode=ReadWrite;Persist Security Info=False;Jet OLEDB:Database Password=111"
' 打开第一个连接
Cn2.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db2.mdb;Mode=ReadWrite;Persist Security Info=False"
' 打开第2个连接

Set Rst2 = Cn2.OpenSchema(adSchemaTables)

Do Until Rst2.EOF
If Rst2!TABLE_NAME = "用户表" Then TableExist = True
Rst2.MoveNext
Loop

If TableExist Then Cn2.Execute "Drop TABLE 用户表"

Cn1.Execute "Select * into " & App.Path & "\db2.mdb.用户表 From 用户表"


End Sub

回复
jhone99 2010-09-26
参考

Private Sub Command1_Click()
Dim db1 As Database
Dim db2 As Database

Set db1 = OpenDatabase(App.Path & "\a.mdb")

db1.Execute ("INSERT INTO [;database=" & App.Path & "\b.mdb;].[员工]([姓名],[性别],[生日]) SELECT [姓名],[性别],[生日] FROM [员工]")



End Sub
回复
相关推荐
发帖

1187

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
帖子事件
创建了帖子
2010-09-26 02:58
社区公告
暂无公告