同样结构数据库,用VBS如何将表ACT的新增一行数据复制到表ACT_1?

  • t
    t526
    Const adUseClient = 3
    Const adStateClosed = 0

    Dim sdate
    Dim Cnt
    Dim maxid
    Dim sleepTime

    Dim fpath
    fpath="D:\JCC120.mdb"

    sleepTime=1500

    Set Conn=CreateObject("adodb.connection")
    Set Rs=CreateObject("ADODB.Recordset")
    Conn.CursorLocation = adUseClient

    strCon="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & fpath & ";Persist Security Info=False"
    Conn.Open strCon


    if Rs.State <> adStateClosed Then Rs.Close
    Rs.Open "select max(id) as mid from Act",Conn
    if Rs.RecordCount > 0 Then
    maxid = rs("mid")
    End If
    Rs.Close
    Conn.Close
    WScript.Echo "程序开始,当前ID: " & maxid

    While 1=1
    Conn.Open strCon
    if Rs.State <> adStateClosed Then Rs.Close
    Rs.Open "SELECT * from Act where id > " & maxid & " order by id" ,Conn
    Cnt = Rs.RecordCount

    If Cnt > 0 Then
    Rs.MoveFirst
    For i = 1 To Cnt
    'WScript.Echo "key="&rs("iTime")&vbcrlf&"a="&rs("NAM_GL1")
    maxid = rs("id")

    SN1 = rs("S6")
    SN2 = rs("S7")
    SN3 = rs("S8")
    SN4 = rs("S9")
    SN5 = rs("S10")
    if SN1 > 0 Then
    SN ="S6"
    SNA = SN1
    elseif SN2 > 0 Then
    SN = "S7"
    SNA = SN2
    elseif SN3 > 0 Then
    SN = "S8"
    SNA = SN3
    elseif SN4 > 0 Then
    SN = "S9"
    SNA = SN4
    elseif SN5 > 0 Then
    SN = "S10"
    SNA = SN5
    end if

    AN = "A"&Right(SN,len(SN)-1)

    Conn.Execute "update Act set " & SN & "=ROUND("& SNA &"+S15) where id=" & rs("ID")
    Conn.Execute "update Act set A1=ROUND(S1*" & rndnum() &"),A2=ROUND(" & rndnum() &"*S2*" & rndnum() &"),A3=ROUND(" & rndnum() &"*S3*" & rndnum() &"),A4=ROUND(" & rndnum() &"*S4*" & rndnum() &")," & AN & "=ROUND((" & rndnum() &"+" & rndnum() &")/2*" & SN & "),A15=0,S15=0,A23=ROUND((" & rndnum() &"+" & rndnum() &")/2*S23,2),A22=ROUND(ROUND(" & rndnum() &"*S22+S22)/2,1),FullMix=FullMix+35 where id=" & rs("ID")
    rs.MoveNext
    Next
    End If

    Rs.Close
    Conn.Close
    WScript.Echo "已处理 " & Cnt & ", 目前ID " & maxid

    ' WScript.Echo "等待" & sleepTime/1000 & "秒"
    Wscript.Sleep sleepTime
    Wend

    Set Rs = Nothing
    Set Conn = Nothing


    Function rndnum()
    Randomize()
    If Rnd() > 0.5 Then
    Randomize()
    rndnum = 1 + Rnd()/100
    Else
    Randomize()
    rndnum = 1 - Rnd()/100
    End If
    End Function
  • t
    t526
    有没有大哥指点下~
    我自己用SQL语句总是提示语句未结束
  • j
    josephduung
    你把几个拼出来的SQL放到变量中,然后MessageBox.Show一下字符串的内容就知道语句拼的有没有问题了