以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  如何按性别排序  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=1586)

--  作者:老有所乐
--  发布时间:2009/1/8 23:17: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"


如果不按班级排序,而是按性别排序,公式该如何修改,谢谢!
[此贴子已经被作者于2009-1-8 23:17:17编辑过]

--  作者:czy
--  发布时间:2009/1/9 0:13: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")

这样应该没有问题了。
--  作者:老有所乐
--  发布时间:2009/1/9 11:05:00
--  

谢谢C版主!原来是这个\'" & bjs(i) & "\'" 问题