Foxtable(狐表)用户栏目专家坐堂 → 这里的第二组代码究竟出错在哪?


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

主题:这里的第二组代码究竟出错在哪?

帅哥哟,离线,有人找我吗?
不同凡响的声音
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:47 积分:608 威望:0 精华:0 注册:2011/9/12 21:40:00
这里的第二组代码究竟出错在哪?  发帖心情 Post By:2011/10/19 20:06:00 [只看该作者]

第一组代码

Dim bjs As List(Of String) = DataTables("九年级全年级").GetUniqueValues("[班别] Is Not NULL","班别")
Dim Count As Integer
Dim ColNames() As String = {"语","数","英","物","化","政","历","总分"}
Dim TotalName As String
For Each ColName As string In ColNames '
    For i As Integer = 0 To bjs.Count -1
        Dim drs As List(Of DataRow) = DataTables("九年级全年级").Select("[班别] = " & bjs(i), ColName & " DESC")
        Count = 0
        TotalName = ColName & "序"
        For n As Integer = 0 To drs.Count - 1
            Count = Count + 1
            If n > 0 AndAlso drs(n)(ColName ) = drs(n-1)(ColName) Then
                drs(n)(TotalName ) = drs(n-1)(TotalName )
            Else
                drs(n)(TotalName ) = Count
            End If
        Next
    Next
Next
Tables("九年级全年级").Sort = "总分 DESC"

 

第二组代码

Dim bjs As List(Of String) = DataTables("九年级全年级").GetUniqueValues("[学校] Is Not NULL","学校")
Dim Count As Integer
Dim ColNames() As String = {"语","数","英","物","化","政","历","总分"}
Dim TotalName As String
For Each ColName As string In ColNames '
    For i As Integer = 0 To bjs.Count -1
        Dim drs As List(Of DataRow) = DataTables("九年级全年级").Select("[学校] = " & bjs(i), ColName & " DESC")
        Count = 0
        TotalName = ColName & "序"
        For n As Integer = 0 To drs.Count - 1
            Count = Count + 1
            If n > 0 AndAlso drs(n)(ColName ) = drs(n-1)(ColName) Then
                drs(n)(TotalName ) = drs(n-1)(TotalName )
            Else
                drs(n)(TotalName ) = Count
            End If
        Next
    Next
Next
Tables("九年级全年级").Sort = "总分 DESC"

 

 文件如下图所示


图片点击可在新窗口打开查看此主题相关图片如下:01.jpg
图片点击可在新窗口打开查看

在这样的文件中运行第一组代码,能正确排序,按班级排

我想要按学校排序,就将第一组代码换成第二组代码,运行时出错,(如下图所示)


图片点击可在新窗口打开查看此主题相关图片如下:02.jpg
图片点击可在新窗口打开查看

不知道何原因,如果要按学校排,第二组代码应该怎么修改呢?请朋友们帮看看,谢谢。

[此贴子已经被作者于2011-10-19 20:07:07编辑过]

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


加好友 发短信
等级:管理员 帖子:47497 积分:251403 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2011/10/19 20:29:00 [只看该作者]

Dim drs As List(Of DataRow) = DataTables("九年级全年级").Select("[学校] = " & bjs(i), ColName & " DESC")

 

应该改为:

 

Dim drs As List(Of DataRow) = DataTables("九年级全年级").Select("[学校] = '" & bjs(i) &  "'" , ColName & " DESC")

 

建议看看:

http://www.foxtable.com/help/topics/1284.htm

 


 回到顶部