在VB6.0中能将一个数据库中查询到的记录插入到另一个数据库吗?
在VB6.0中能将一个数据库中查询到的记录插入到另一个数据库吗?数据库结构一样的。如果能,麻烦写一下代码或语句。谢谢。情况是这样的,insertintoTblShipNo...
在VB6.0中能将一个数据库中查询到的记录插入到另一个数据库吗?数据库结构一样的。如果能,麻烦写一下代码或语句。谢谢。
情况是这样的,insert into TblShipNo select * from TblShipNo
这条SQL语句如果目标表和源表不属于同一数据库,而是各自属于各自的数据库,而且这两个表名还是一样的,应该怎么写SQL语句,谢谢高手指点。 展开
情况是这样的,insert into TblShipNo select * from TblShipNo
这条SQL语句如果目标表和源表不属于同一数据库,而是各自属于各自的数据库,而且这两个表名还是一样的,应该怎么写SQL语句,谢谢高手指点。 展开
3个回答
展开全部
可以实现,供你参考
Dim Conn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Tbcs08D.MDB;Persist Security Info=False"
Conn.Open
Rs.CursorLocation = adUseClient
Rs.Open "select * from Invoice Where InvoiceName='" & P_InvoiceName & "' ", Conn, 1, 3
Dim a(16) As String
Dim G As Integer
For G = 0 To 15
If Rs.EOF <> True Then '定单名称不存在时,跳过赋值语句,避免提示提示EOF或BOF为真,A(G)赋空值。
a(G) = Rs.Fields(G)
Else
Select Case G
Case 0, 1, 2, 3, 4, 7, 8, 9, 10, 11, 12, 13, 14, 15
a(G) = ""
Case 5, 6
a(G) = 0
End Select
End If
'Print "a" & G & "="; A(G)
Next G
Rs.Close
Conn.Close
'***存目标值、实际值***
Dim ConnBc As New ADODB.Connection
Dim SqlStrBc As String
ConnBc.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Tbcs08D.MDB;Persist Security Info=False"
ConnBc.Open
If P_Batch = 1 Then
If FileIniRead(App.Path & "\" & "TbcsSet.ini", "Memory2", "存盘罐次", "-1") <> 1 Then '避免存盘时退出程序再进时多次存目标值
Call FileIniWrite(App.Path & "\" & "TbcsSet.ini", "Memory2", "存盘罐次", 0)
jarTimes = P_Batch - 1 & " " & "目标值" '送目标值。罐次前面加序号,时间相同时再按罐次排序
SqlStrBc = "Insert Into SaveData Values ('" & LblInvoiceCode & "','" & LblFormula & "','" & Date + Time & "','" & a(1) & "','" & a(2) & "','" & a(3) & "' ,'" & a(4) & "','" & LblQt(1) & "','" & LblQt(2) & "','" & a(7) & "','" & a(8) & "','" & jarTimes & "','" & CmbSquareCar & "','" & LblPb(1) & "','" & LblPb(2) & "','" & LblPb(3) & "','" & LblPb(4) & "','" & LblPb(5) & "','" & LblPb(6) & "','" & LblPb(7) & "','" & LblPb(8) & "','" & Val(P_WaterFinal) & "','0','" & LblPb(10) & "','" & LblPb(11) & "','" & LblPb(12) & "','" & LblPb(13) & "','" & LblPb(14) & "','" & LblPb(15) & "')"
ConnBc.Execute (SqlStrBc) '存盘表写入目标值
End If
End If
我上面代码所实现的功能是从一个数据库中查找定单信息,将这些信息提取出来,加上采集上来的数据组成一条新记录写入另一个数据库中。供你参考。
Dim Conn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Tbcs08D.MDB;Persist Security Info=False"
Conn.Open
Rs.CursorLocation = adUseClient
Rs.Open "select * from Invoice Where InvoiceName='" & P_InvoiceName & "' ", Conn, 1, 3
Dim a(16) As String
Dim G As Integer
For G = 0 To 15
If Rs.EOF <> True Then '定单名称不存在时,跳过赋值语句,避免提示提示EOF或BOF为真,A(G)赋空值。
a(G) = Rs.Fields(G)
Else
Select Case G
Case 0, 1, 2, 3, 4, 7, 8, 9, 10, 11, 12, 13, 14, 15
a(G) = ""
Case 5, 6
a(G) = 0
End Select
End If
'Print "a" & G & "="; A(G)
Next G
Rs.Close
Conn.Close
'***存目标值、实际值***
Dim ConnBc As New ADODB.Connection
Dim SqlStrBc As String
ConnBc.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Tbcs08D.MDB;Persist Security Info=False"
ConnBc.Open
If P_Batch = 1 Then
If FileIniRead(App.Path & "\" & "TbcsSet.ini", "Memory2", "存盘罐次", "-1") <> 1 Then '避免存盘时退出程序再进时多次存目标值
Call FileIniWrite(App.Path & "\" & "TbcsSet.ini", "Memory2", "存盘罐次", 0)
jarTimes = P_Batch - 1 & " " & "目标值" '送目标值。罐次前面加序号,时间相同时再按罐次排序
SqlStrBc = "Insert Into SaveData Values ('" & LblInvoiceCode & "','" & LblFormula & "','" & Date + Time & "','" & a(1) & "','" & a(2) & "','" & a(3) & "' ,'" & a(4) & "','" & LblQt(1) & "','" & LblQt(2) & "','" & a(7) & "','" & a(8) & "','" & jarTimes & "','" & CmbSquareCar & "','" & LblPb(1) & "','" & LblPb(2) & "','" & LblPb(3) & "','" & LblPb(4) & "','" & LblPb(5) & "','" & LblPb(6) & "','" & LblPb(7) & "','" & LblPb(8) & "','" & Val(P_WaterFinal) & "','0','" & LblPb(10) & "','" & LblPb(11) & "','" & LblPb(12) & "','" & LblPb(13) & "','" & LblPb(14) & "','" & LblPb(15) & "')"
ConnBc.Execute (SqlStrBc) '存盘表写入目标值
End If
End If
我上面代码所实现的功能是从一个数据库中查找定单信息,将这些信息提取出来,加上采集上来的数据组成一条新记录写入另一个数据库中。供你参考。
展开全部
dim con as adodb.connection
con的链接字符串区分开!
或者是不同的数据源
各自操作各自的,不影响!
con的链接字符串区分开!
或者是不同的数据源
各自操作各自的,不影响!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
直接用insert或者update语句不就行了?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询