VB代码怎么写 20
请问VB代码中,同时操作二个数据库,比如xiafa.mdb的xiafabiao表和saletmp.mdb中的Goods表中的商品编号相同的,更新Goods表中的零售价=x...
请问VB代码中,同时操作二个数据库,比如xiafa.mdb的xiafabiao表和saletmp.mdb中的Goods表中的商品编号相同的,更新Goods表中的零售价=xiafabiao中的新零售价
展开
1个回答
展开全部
Public conn As New ADODB.Connection
Public conn1 As New ADODB.Connection
Public ConnString As String
Public ConnString1 As String
Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset
dim sql as string
dim sql1 as string
ConnString1 = "provider=microsoft.jet.oledb.4.0;" & _
"data source=" & App.Path & "\xiafa.mdb;Jet OLEDB:"
If conn1.state <> 1 Then
conn1.Open (ConnString1)
End If
ConnString = "provider=microsoft.jet.oledb.4.0;" & _
"data source=" & App.Path & "\saletmp.mdb;Jet OLEDB:"
If conn.state <> 1 Then
conn.Open (ConnString)
End If
sql = "select * from xiafabiao"
sql1="select * from Goods"
rs.Open sql, conn, adOpenKeyset, adLockPessimistic
rs1.Open sql, conn1, adOpenKeyset, adLockPessimistic
rs.movefirst
do while not rs.eof()
rs1.movefirst
do while not rs1.eof()
if rs.Fields(0)=rs1.field(0) then;此处假设商品编号在你的两个表中都是第一个字段
;更新Goods表的字段
endif
rs1.movenext
loop
rs.movenext
loop
大体思路是这样,小细节可以再改改
Public conn1 As New ADODB.Connection
Public ConnString As String
Public ConnString1 As String
Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset
dim sql as string
dim sql1 as string
ConnString1 = "provider=microsoft.jet.oledb.4.0;" & _
"data source=" & App.Path & "\xiafa.mdb;Jet OLEDB:"
If conn1.state <> 1 Then
conn1.Open (ConnString1)
End If
ConnString = "provider=microsoft.jet.oledb.4.0;" & _
"data source=" & App.Path & "\saletmp.mdb;Jet OLEDB:"
If conn.state <> 1 Then
conn.Open (ConnString)
End If
sql = "select * from xiafabiao"
sql1="select * from Goods"
rs.Open sql, conn, adOpenKeyset, adLockPessimistic
rs1.Open sql, conn1, adOpenKeyset, adLockPessimistic
rs.movefirst
do while not rs.eof()
rs1.movefirst
do while not rs1.eof()
if rs.Fields(0)=rs1.field(0) then;此处假设商品编号在你的两个表中都是第一个字段
;更新Goods表的字段
endif
rs1.movenext
loop
rs.movenext
loop
大体思路是这样,小细节可以再改改
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询