以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  多条记录状态变更  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=173155)

--  作者:nuoyan89
--  发布时间:2021/11/17 8:47:00
--  多条记录状态变更

老师,我一个表里会有多条记录,但是以下这个代码只能变更当前一条记录,我想多条记录同时变,请帮忙看看,谢谢!

    Dim dr5 As Row = Tables("刀具领用计划_计划明细").current
    If Tables("刀具领用计划_计划明细").current  IsNot  Nothing
        Dim  drs1 As  List(of  DataRow) = DataTables("库存明细记录").SQLSelect("刀具代码 = \'" & dr5("刀具代码") & "\' And 单刀编码= \'" & dr5("单刀编码") & "\' And 材料编码 = \'" & dr5("材料编码") & "\'")
        For Each  dr6 As  DataRow In drs1
            dr6("目前状态") = "领用"
            dr6("库位") = "生产车间"
        Next
        DataTables("库存明细记录").SQLUpdate(drs1)
    End  If
    DataTables("库存明细记录").load


--  作者:有点蓝
--  发布时间:2021/11/17 8:59:00
--  
遍历所有行参考:http://www.foxtable.com/webhelp/topics/1438.htm
--  作者:nuoyan89
--  发布时间:2021/11/17 9:06:00
--  

我改成了如下,但是依然会有状态变不过来的

 

For Each dr3 As Row In Tables("刀具领用计划_计划明细").Rows
    Dim  drs As  List(of  DataRow) = DataTables("库存明细记录").SQLSelect("刀具代码 = \'" & dr3("刀具代码") & "\' And 单刀编码= \'" & dr3("单刀编码") & "\' And 材料编码 = \'" & dr3("材料编码") & "\'")
    For Each  dr As  DataRow In drs
        dr("目前状态") = "领用"
        dr("库位") = "生产车间"
    Next
    DataTables("库存明细记录").SQLUpdate(drs)
Next
DataTables("库存明细记录").load


--  作者:有点蓝
--  发布时间:2021/11/17 9:17:00
--  
应该是数据有问题,SQLSelect是否已经查询到所有行的数据了
For Each dr3 As Row In Tables("刀具领用计划_计划明细").Rows
    Dim  drs As  List(of  DataRow) = DataTables("库存明细记录").SQLSelect("刀具代码 = \'" & dr3("刀具代码") & "\' And 单刀编码= \'" & dr3("单刀编码") & "\' And 材料编码 = \'" & dr3("材料编码") & "\'")
msgbox(drs.count) \'到后台数据库看看符合条件的记录是不是有这么多行
……
DataTables("库存明细记录").SQLUpdate(drs) 
msgbox(1)\'执行后暂停一下,到后台数据库看看数据是否有更新保存
Next
……