Rss & SiteMap
Foxtable(狐表) http://www.foxtable.com
由于temptable表是在递归函数中动态增加记录的,所以不能用FOR each 遍历,会出现异常。
循环遍历temptable临时表,读取行记录后删除行,直到该表记录行为空,用以下格式遍历,应该怎么样写如下两个语句:
1.终止条件
2.下一条记录指令
do while (终止条件【表中无记录时】)
’读取当前记录
’删除当前记录
’下一条记录指令
loop
For each dr dataRow in DataTables("xxx")
'循环读取
next
DataTables("xxx").DataRows.Clear '全部删除
这样可以吗:
for i as integer = tables("临时表").count-1 to 0 step -1
..........
next
For Each r As DataRow In DataTables("tempbom").DataRows
If r IsNot Nothing Then
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
End If
Next
很奇怪,一样的代码,刚刚试是正确的,在之前就是在TEMPBOM中有一条记录无法删除。
没有看懂,避免出错的方法:
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
Dim cnt As Integer = DataTables("tempbom").DataRows.Count -1
这句代码是用来做诱的吧。。
哈哈。。还是要感谢你的支持和帮助,只要不出错就OK~