用rs.addnew往数据库里面插入3跳数据,结果只有一条,好像每次执行addnew的时候没有插入,反而更新了,请问是何原因,多谢!

解决方案 »

  1.   

    rs.AddNew
    rs!Name = "xxxxxxx"
    rs!Password = "ssssss"
    rs.Update'每次添加完成一条都要执行这个Updaters.AddNew
    rs!Name = "xxxxxxx"
    rs!Password = "ssssss"
    rs.Update
      

  2.   

    每次添加完成一条都要执行这个Update
      

  3.   

    我遇到同样的问题,按你所讲的用.update方法都是只能修改,而不能添加。
      

  4.   

    我的代码:我在循环里面用的rd.addnew  rd.update,看不出错在那里。
    请多多帮忙!
      

  5.   

    addnew以后没有马上update,后面继续addnew的话就会更新前面的,所以注意下你的循环
      

  6.   

    tztz520(午夜逛街) ( ) 的这个是完全正确的,如果还有问题,你可以检查一下记录集是否有问题!
    rs.AddNew
    rs!Name = "xxxxxxx"
    rs!Password = "ssssss"
    rs.Update'每次添加完成一条都要执行这个Update
      

  7.   

    查看rs的属性:LockType和CursorType
      

  8.   

    rs.CursorType = adOpenKeyset
    rs.LockType = adLockOptimistic我在addnew以后确实马上update了。因为我在别的form里面addnew没有问题。所以我也怀疑是代码的问题,可是找不到问题:(请问记录集可能会出现什么问题?
      

  9.   

    '不可能有什么问题/肯定代码哪里 给delete 或 addnew--update没有成对出现
    for i=0 to 2
    rs.AddNew
    rs!Name = "xxxxxxx"
    rs!Password = "ssssss"
    rs.Update'每次添加完成一条都要执行这个Update
    next
      

  10.   

    相关代码请大家看看有什么问题:
      rs2.CursorLocation = adUseClient
      rs2.CursorType = adOpenKeyset
      rs2.LockType = adLockOptimistic  sql = "select * from CZBYSWZFPZ where CITRDT='" + CStr(Format((Form3.DTPicker1.Value), "yyyymmdd")) + "' and CIFSNO=''"
      Set rs = db.Execute(sql)
      
      '往临时表写明细信息
      Dim row As Integer
      row = 1
      
      '打开临时表
      rs2.Open "CZBYSWPZMXtmp", db, , , adCmdTable
        
      If Not rs.EOF Then  '第一次生成此明细回单
          Do While Not rs.EOF
            '取信息
            tt_cihdno = CStr(Format(Date, "yyyymmdd")) + Text1.Text
            tt_cipybm = Trim(rs.Fields("CIPYBM"))
            tt_cipyac = Trim(rs.Fields("CIPYAC"))
            
            sql = "select sum(CIZFAM) as zfam1 from CZBYSWZFPZ where CITRDT='" + CStr(Format((Form3.DTPicker1.Value), "yyyymmdd")) + "' and CIZFAM>0 and CIFSNO=''"
            Set rs3 = db.Execute(sql)
            tt_cihdtl = CStr(rs3.Fields("zfam1"))
            'tt_cihdtl = CStr(db.Execute(sql))
            
            sql = "select sum(CIZFAM) as zfam2 from CZBYSWZFPZ where CITRDT='" + CStr(Format((Form3.DTPicker1.Value), "yyyymmdd")) + "' and CIZFAM<0 and CIFSNO=''"
            Set rs3 = db.Execute(sql)
            If IsNull(rs3.Fields("zfam2")) = True Then
                tt_citptl = "0.00"
            Else
                tt_citptl = CStr(rs3.Fields("zfam2"))
            End If
            'tt_citptl = CStr(db.Execute(sql))
            
            sql = "select count(*) as rotl from CZBYSWZFPZ where CITRDT='" + CStr(Format((Form3.DTPicker1.Value), "yyyymmdd")) + "' and CIFSNO=''"
            Set rs3 = db.Execute(sql)
            tt_cirotl = CStr(rs3.Fields("rotl"))
            'tt_cirotl = CStr(db.Execute(sql))
            
            tt_cirono = CStr(row)
            tt_cidjlx = Left(cidjlx, 2)
            tt_cipydt = Trim(rs.Fields("CITRDT"))
            tt_cifhno = Trim(rs.Fields("CIPNNO"))
            tt_cizfam = CStr(Trim(rs.Fields("CIZFAM")))
            tt_ciy1no = Trim(rs.Fields("CIY1NO"))
            tt_ciitid = Trim(rs.Fields("CIITID"))
            tt_ciecfg = Trim(rs.Fields("CIECFG"))
            tt_cirvac = Trim(rs.Fields("CIRVAC"))
            
            If citpyy = "全部" Then
                tt_citpyy = ""
            Else
                tt_citpyy = Left(citpyy, 2)
            End If
            
            tt_cipati = cipati
            tt_ciinno = Trim(rs.Fields("CIINNO"))
            tt_ciamfg = Trim(rs.Fields("CIAMFG"))
            tt_ciamug = Trim(rs.Fields("CIAMUG"))
            tt_ciywdy = Trim(rs.Fields("CIYWDY"))
            tt_ciszgl = Trim(rs.Fields("CISZGL"))
            tt_ciprid = Trim(rs.Fields("CIPRID"))
            tt_cifsno = Trim(Text1.Text)
            
            '写数据库
            '清空临时表
            db.Execute ("delete from CZBYSWPZMXtmp")
            
            '写数据进临时表
            'Set rs2 = db.Execute("select * from CZBYSWPZMXtmp")
            'rs2.Open "CZBYSWPZMXtmp", db, , , adCmdTable
            rs2.AddNew
              rs2.Fields("CIHDNO").Value = tt_cihdno
              rs2.Fields("CIPYBM").Value = tt_cipybm
              rs2.Fields("CIPYAC").Value = tt_cipyac
              
              If tt_cihdtl <> "0.00" Then
                rs2.Fields("CIHDTL").Value = CDbl(tt_cihdtl)
              End If
              
              rs2.Fields("CITPTL").Value = CDbl(tt_citptl)
              rs2.Fields("CIROTL").Value = CLng(tt_cirotl)
              rs2.Fields("CIRONO").Value = CLng(tt_cirono)
              rs2.Fields("CIDJLX").Value = tt_cidjlx
              rs2.Fields("CIPYDT").Value = tt_cipydt
              rs2.Fields("CIFHNO").Value = tt_cifhno
              rs2.Fields("CIZFAM").Value = CDbl(tt_cizfam)
              rs2.Fields("CIY1NO").Value = tt_ciy1no
              rs2.Fields("CIITID").Value = tt_ciitid
              rs2.Fields("CIECFG").Value = tt_ciecfg
              rs2.Fields("CIRVAC").Value = tt_cirvac
              rs2.Fields("CITPYY").Value = tt_citpyy
              rs2.Fields("CIPATI").Value = tt_cipati
              rs2.Fields("CIINNO").Value = tt_ciinno
              rs2.Fields("CIAMFG").Value = tt_ciamfg
              rs2.Fields("CIAMUG").Value = tt_ciamug
              rs2.Fields("CIYWDY").Value = tt_ciywdy
              rs2.Fields("CISZGL").Value = tt_ciszgl
              rs2.Fields("CIYWLX").Value = tt_ciywlx
              rs2.Fields("CIPRID").Value = tt_ciprid
              rs2.Fields("CIFSNO").Value = tt_cifsno
            rs2.Update
            row = row + 1
            rs.MoveNext
          Loop