Foxtable(狐表)用户栏目专家坐堂 → 请教循环遍历结构问题


  共有11177人关注过本帖树形打印复制链接

主题:请教循环遍历结构问题

帅哥哟,离线,有人找我吗?
狐狸爸爸
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47448 积分:251048 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2011/11/29 22:16:00 [显示全部帖子]

For each dr dataRow in DataTables("xxx")

   '循环读取

next

DataTables("xxx").DataRows.Clear '全部删除


 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47448 积分:251048 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2011/11/29 23:33:00 [显示全部帖子]

For i As Integer = DataTables("tempbom").DataRows.Count -1  To 0 Step -1
    Dim r As DataRow = DataTables("tempbom").DataRow(i)
    Dim dt1 As DataTable
    Dim cmd1 As New SQLCommand
    Dim curgoid As Integer
    curgoid = r("goid")
    r.Delete
    cmd1.CommandText = "Select goid,singletotal,comgoid,sf_nonstock From {cp_singlebom} Inner JOIN {product} ON {product}.[_Identify] = {cp_singlebom}.[goid]  where {cp_singlebom}.[goid]=" & CSTR(curgoid)
    dt1 = cmd1.ExecuteReader()
    If dt1.DataRows.Count > 0 Then
        '循环调用自身函数
    Else
        '追加到数据表中
        Dim r1 As Row = Tables("bomdata").AddNew()
        r1("goid") = curgoid
        ' r("singletotal")=dr("singletotal")
        ' r("sf_summy")= dr("sf_nonstock")
        ' r("sortkey")= Initcnt
    End If
Next
[此贴子已经被作者于2011-11-29 23:32:49编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47448 积分:251048 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2011/11/30 11:55:00 [显示全部帖子]

没有看懂,避免出错的方法:

 

Public Function GenProductBom(ByVal rootid As Integer,ByVal goid As Integer,ByVal formatstr As String,ByVal NeedTotal As Double,ByVal onetotal As Double) As Boolean
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.CommandText ="Select goid,singletotal,comgoid,sf_nonstock,ord From {cp_singlebom} Inner JOIN {product} ON {product}.[_Identify] = {cp_singlebom}.[goid]  where {cp_singlebom}.[goid]=" & Cstr(goid)
dt = cmd.ExecuteReader()
Dim r2 As Row = Tables("bomdata").AddNew()
r2("goid") = rootid
r2("nodegoid") = goid
r2("sortkey") = Formatstr
r2("total") = NeedTotal
r2("Singletotal") = onetotal

If dt.DataRows.Count > 0 Then
    For Each dr As DataRow In dt.DataRows
        Dim r As Row = Tables("tempbom").AddNew()
        r("goid")=dr("comgoid")
        r("singletotal") = dr("singletotal")
        r("total") = dr("singletotal") * NeedTotal
        r("sortkey")= Formatstr + "/" + Format(dr("ord"),"000")
    Next
End If

Dim cnt As Integer = DataTables("tempbom").DataRows.Count -1

Do While DataTables("tempbom").DataRows.Count > 0
    Dim r  As DataRow = DataTables("tempbom").DataRows(0)
    Dim dt1 As DataTable
    Dim cmd1 As New SQLCommand
    Dim curgoid As Integer
    Dim fstr As String
    Dim curSingletotal As Double = r("singletotal")
    Dim curTotal As Double = r("total")
    curgoid = r("goid")
    fstr = r("sortkey")
    'MessageBox.Show(cstr(curgoid),"info",MessageBoxButtons.OK,MessageBoxIcon.Information)
    r.Delete
    cmd1.CommandText = "Select goid,singletotal,comgoid,sf_nonstock,ord From {cp_singlebom} Inner JOIN {product} ON {product}.[_Identify] = {cp_singlebom}.[goid]  where {cp_singlebom}.[goid]=" & CSTR(curgoid)
    dt1 = cmd1.ExecuteReader()
   
    If dt1.DataRows.Count > 0 Then
        GenProductBom(rootid,curgoid,fstr,curtotal,cursingletotal)
    Else
        '追加到数据表中
        Dim r1 As Row = Tables("bomdata").AddNew()
        r1("goid") = rootid
        r1("nodegoid") = curgoid
        r1("sortkey") = fstr
        r1("singletotal")=cursingletotal
        'r1("sf_summy")= dr("sf_nonstock")
        r1("total")= curtotal
    End If
Loop
Return True
End Function

[此贴子已经被作者于2011-11-30 11:55:28编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47448 积分:251048 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2011/11/30 12:15:00 [显示全部帖子]

这是多余的一行代码,删除即可。

 回到顶部