主题:关于跨数据库查询
Private Sub Timer2_Timer()
On Error Resume Next
' TabMsg
Dim rstTrackinfoAccess As ADODB.Recordset
' 打开TabMsg
Set rstTrackinfoAccess = New ADODB.Recordset
Dim cmdCgb As New ADODB.Command
Set cmdCgb.ActiveConnection = connAccess 'connSqlServer
rstTrackinfoAccess.CursorType = adOpenKeyset
rstTrackinfoAccess.LockType = adLockReadOnly 'adLockOptimistic
Dim strSql As String
strSql = "select sysid,FaBRQ,FuJXX from WL_information_Che where ChuFDid = 1508 order by sysid desc "
cmdCgb.CommandText = strSql
rstTrackinfoAccess.CursorType = adOpenKeyset
rstTrackinfoAccess.LockType = adLockReadOnly
rstTrackinfoAccess.Open cmdCgb, , adOpenKeyset, adLockReadOnly
' 本地信息SqlServer
Dim rstTrackinfoSqlServer As ADODB.Recordset
' 打开本地信息表SqlServer
Set rstTrackinfoSqlServer = New ADODB.Recordset
DateTime = Now
Dim sqlInsert As String
If Not rstTrackinfoAccess.EOF Then
rstTrackinfoAccess.MoveFirst
End If
Do While Not rstTrackinfoAccess.EOF
Dim cmdCgbSqlServer As New ADODB.Command
Set cmdCgbSqlServer.ActiveConnection = connSqlServe
strSql = "SELECT count(*) as sumCount from info_from where info_id = " & rstTrackinfoAccess(info_id)
cmdCgbSqlServer.CommandText = strSql
'rstTrackinfoAccess.Open cmdCgbAccess, , adOpenStatic, adLockBatchOptimistic
rstTrackinfoSqlServer.Open cmdCgbSqlServer, , adOpenKeyset, adLockReadOnly
rstTrackinfoSqlServer.MoveFirst
If IsNull(rstTrackinfoSqlServer("sumCount")) Or rstTrackinfoSqlServer("sumCount") = 0 Then
sqlInsert = " insert into info_from(inff_prov,inff_disc,info_id,post_date,info_rela,infs_oths) values( 山西,运城, '" & rstTrackinfoAccess(sysid) & "','" & DateTime & "',渭南物流,'" & rstTrackinfoAccess(FuJXX) & "')"
connSqlServer.Execute sqlInsert
End If
rstTrackinfoSqlServer.Close
rstTrackinfoAccess.MoveNext
Loop
rstTrackinfoAccess.Close
End Sub
中的 strSql = "SELECT count(*) as sumCount from info_from where info_id = " & rstTrackinfoAccess(info_id)这句中的rstTrackinfoAccess(info_id)什么意思?
是函数调用吗?
On Error Resume Next
' TabMsg
Dim rstTrackinfoAccess As ADODB.Recordset
' 打开TabMsg
Set rstTrackinfoAccess = New ADODB.Recordset
Dim cmdCgb As New ADODB.Command
Set cmdCgb.ActiveConnection = connAccess 'connSqlServer
rstTrackinfoAccess.CursorType = adOpenKeyset
rstTrackinfoAccess.LockType = adLockReadOnly 'adLockOptimistic
Dim strSql As String
strSql = "select sysid,FaBRQ,FuJXX from WL_information_Che where ChuFDid = 1508 order by sysid desc "
cmdCgb.CommandText = strSql
rstTrackinfoAccess.CursorType = adOpenKeyset
rstTrackinfoAccess.LockType = adLockReadOnly
rstTrackinfoAccess.Open cmdCgb, , adOpenKeyset, adLockReadOnly
' 本地信息SqlServer
Dim rstTrackinfoSqlServer As ADODB.Recordset
' 打开本地信息表SqlServer
Set rstTrackinfoSqlServer = New ADODB.Recordset
DateTime = Now
Dim sqlInsert As String
If Not rstTrackinfoAccess.EOF Then
rstTrackinfoAccess.MoveFirst
End If
Do While Not rstTrackinfoAccess.EOF
Dim cmdCgbSqlServer As New ADODB.Command
Set cmdCgbSqlServer.ActiveConnection = connSqlServe
strSql = "SELECT count(*) as sumCount from info_from where info_id = " & rstTrackinfoAccess(info_id)
cmdCgbSqlServer.CommandText = strSql
'rstTrackinfoAccess.Open cmdCgbAccess, , adOpenStatic, adLockBatchOptimistic
rstTrackinfoSqlServer.Open cmdCgbSqlServer, , adOpenKeyset, adLockReadOnly
rstTrackinfoSqlServer.MoveFirst
If IsNull(rstTrackinfoSqlServer("sumCount")) Or rstTrackinfoSqlServer("sumCount") = 0 Then
sqlInsert = " insert into info_from(inff_prov,inff_disc,info_id,post_date,info_rela,infs_oths) values( 山西,运城, '" & rstTrackinfoAccess(sysid) & "','" & DateTime & "',渭南物流,'" & rstTrackinfoAccess(FuJXX) & "')"
connSqlServer.Execute sqlInsert
End If
rstTrackinfoSqlServer.Close
rstTrackinfoAccess.MoveNext
Loop
rstTrackinfoAccess.Close
End Sub
中的 strSql = "SELECT count(*) as sumCount from info_from where info_id = " & rstTrackinfoAccess(info_id)这句中的rstTrackinfoAccess(info_id)什么意思?
是函数调用吗?