以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]用得很好的代码突然报错……  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=40727)

--  作者:zhuzhi
--  发布时间:2013/9/27 15:05:00
--  [求助]用得很好的代码突然报错……
Dim dt As DataTable = DataTables("异动总表")
Dim nums As List(Of String) = dt.GetUniqueValues("学号 is not null", "学号")
Dim idxs As String = ""
For Each num As String In nums
    Dim drs As List(Of DataRow) = dt.Select("学号 = \'" & num & "\'", "异动日期")
    For i As Integer = drs.Count - 2 To 0 Step -1
        Dim bf As DataTable = DataTables("异动备份")
        Dim ndr As DataRow = bf.AddNew()
        For Each c As DataCol In bf.DataCols
            ndr(c.Name) = drs(i)(c.Name)
        Next
        idxs = idxs & drs(i)("_Identify") & ","
    Next
Next

dt.DeleteFor("_Identify in (" & idxs.Trim(",") & ")")

运行之后,显示
图片点击可在新窗口打开查看此主题相关图片如下:报错.jpg
图片点击可在新窗口打开查看
请问这可能是什么原因啊

5天前我还用得很好……

--  作者:Bin
--  发布时间:2013/9/27 15:08:00
--  
你弹出一下你拼接的 idxs 看看就知道了.   
--  作者:jspta
--  发布时间:2013/9/27 15:29:00
--  

idxs是个空值,就报错了

 


--  作者:zhuzhi
--  发布时间:2013/9/27 16:04:00
--  
idxs是什么意思啊,是在哪里弹出呢?
--  作者:Bin
--  发布时间:2013/9/27 16:09:00
--  
额.... 这个不是你写的代码吗?  idxs不是你自己声明的变量嘛?  messagebox.show(idxs)弹出啊.

晕死,混了2年了.怎么这个都没搞清楚.

--  作者:狐狸爸爸
--  发布时间:2013/9/27 17:04:00
--  
判断一下,有符合条件的行才执行:
 
Dim dt As DataTable = DataTables("异动总表")
Dim nums As List(Of String) = dt.GetUniqueValues("学号 is not null", "学号")
Dim idxs As String = ""
For Each num As String In nums
    Dim drs As List(Of DataRow) = dt.Select("学号 = \'" & num & "\'", "异动日期")
    For i As Integer = drs.Count - 2 To 0 Step -1
        Dim bf As DataTable = DataTables("异动备份")
        Dim ndr As DataRow = bf.AddNew()
        For Each c As DataCol In bf.DataCols
            ndr(c.Name) = drs(i)(c.Name)
        Next
        idxs = idxs & drs(i)("_Identify") & ","
    Next
Next
If idxs > "" Then
    dt.DeleteFor("[_Identify] in (" & idxs.Trim(",") & ")")
End If