以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 对后台数据排序 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=93459) |
||||
-- 作者:刘林 -- 发布时间:2016/11/29 14:37:00 -- 对后台数据排序 Dim dt As DataTable = DataTables("成绩") Dim Arys As List(Of String()) = dt.GetValues("考试名称|学校代码|年级代码") For Each Ary As String() In Arys Dim drs As List(Of DataRow) = dt.Select("[考试名称] = \'" & ary(0) & "\'And [学校代码] = \'" & ary(1) & "\'and [年级代码] =\'" & ary(2) & "\'", "折总 DESC") For n As Integer = 0 To drs.Count - 1 \'遍历所有行 If n > 0 AndAlso drs(n)("折总") = drs(n-1)("折总") Then \'如果总分和上一行相同 drs(n)("校序") = drs(n-1)("校序") \'则排名等于上一行 Else drs(n)("校序") = n + 1 \'设置排名 End If Next Next Dim Arys1 As List(Of String()) = dt.GetValues("考试名称|学校代码|年级代码|班级") For Each Ary1 As String() In Arys1 Dim drs As List(Of DataRow) = dt.Select("[考试名称] = \'" & ary1(0) & "\'And [学校代码] = \'" & ary1(1) & "\'and [年级代码] =\'" & ary1(2) & "\'And [班级] = \'" & ary1(3) & "\'", "折总 DESC") For m As Integer = 0 To drs.Count - 1 \'遍历所有行 If m > 0 AndAlso drs(m)("折总") = drs(m-1)("折总") Then \'如果总分和上一行相同 drs(m)("班序") = drs(m-1)("班序") \'则排名等于上一行 Else drs(m)("班序") = m + 1 \'设置排名 End If Next Next dt.save() 老师,我改了个代码是想对成绩进行后台排名次,因为现在这样只能对加载了的数据排序,问题就会造成每次因加载的数据不一样,排序结果就变了,请老师指导下如何能直接后台把名次排出来。请指教
|
||||
-- 作者:刘林 -- 发布时间:2016/11/29 14:38:00 -- Dim cmd As New SQLCommand Dim dt As DataTable = DataTables("成绩") cmd.c cmd.CommandText = "SEL ECT * From {成绩}" dt = cmd.ExecuteReader() \'\'Dim dt As DataTable = DataTables("成绩") Dim Arys As List(Of String()) = dt.GetValues("考试名称|学校代码|年级代码") For Each Ary As String() In Arys Dim drs As List(Of DataRow) = dt.sqlSelect("[考试名称] = \'" & ary(0) & "\'And [学校代码] = \'" & ary(1) & "\'and [年级代码] =\'" & ary(2) & "\'", "折总 DESC") For n As Integer = 0 To drs.Count - 1 \'遍历所有行 If n > 0 AndAlso drs(n)("折总") = drs(n-1)("折总") Then \'如果总分和上一行相同 drs(n)("校序") = drs(n-1)("校序") \'则排名等于上一行 Else drs(n)("校序") = n + 1 \'设置排名 End If Next Next Dim Arys1 As List(Of String()) = dt.GetValues("考试名称|学校代码|年级代码|班级") For Each Ary1 As String() In Arys1 Dim drs As List(Of DataRow) = dt.sqlSelect("[考试名称] = \'" & ary1(0) & "\'And [学校代码] = \'" & ary1(1) & "\'and [年级代码] =\'" & ary1(2) & "\'And [班级] = \'" & ary1(3) & "\'", "折总 DESC") For m As Integer = 0 To drs.Count - 1 \'遍历所有行 If m > 0 AndAlso drs(m)("折总") = drs(m-1)("折总") Then \'如果总分和上一行相同 drs(m)("班序") = drs(m-1)("班序") \'则排名等于上一行 Else drs(m)("班序") = m + 1 \'设置排名 End If Next Next dt.save() \'\'DataTables("成绩").SQLUpdate 改成了上面的代码没反应
|
||||
-- 作者:有点蓝 -- 发布时间:2016/11/29 15:03:00 -- 你改过头了,用了SQLCommand就没有必要sqlSelect了 Dim cmd As New SQLCommand Dim dt As DataTable = DataTables("成绩") cmd.c cmd.CommandText = "SELeCT * From {成绩}" dt = cmd.ExecuteReader() \'\'Dim dt As DataTable = DataTables("成绩") Dim Arys As List(Of String()) = dt.GetValues("考试名称|学校代码|年级代码") For Each Ary As String() In Arys Dim drs As List(Of DataRow) = dt.Select("[考试名称] = \'" & ary(0) & "\'And [学校代码] = \'" & ary(1) & "\'and [年级代码] =\'" & ary(2) & "\'", "折总 DESC") For n As Integer = 0 To drs.Count - 1 \'遍历所有行 If n > 0 AndAlso drs(n)("折总") = drs(n-1)("折总") Then \'如果总分和上一行相同 drs(n)("校序") = drs(n-1)("校序") \'则排名等于上一行 Else drs(n)("校序") = n + 1 \'设置排名 End If Next Next Dim Arys1 As List(Of String()) = dt.GetValues("考试名称|学校代码|年级代码|班级") For Each Ary1 As String() In Arys1 Dim drs As List(Of DataRow) = dt.Select("[考试名称] = \'" & ary1(0) & "\'And [学校代码] = \'" & ary1(1) & "\'and [年级代码] =\'" & ary1(2) & "\'And [班级] = \'" & ary1(3) & "\'", "折总 DESC") For m As Integer = 0 To drs.Count - 1 \'遍历所有行 If m > 0 AndAlso drs(m)("折总") = drs(m-1)("折总") Then \'如果总分和上一行相同 drs(m)("班序") = drs(m-1)("班序") \'则排名等于上一行 Else drs(m)("班序") = m + 1 \'设置排名 End If Next Next dt.save() |
||||
-- 作者:刘林 -- 发布时间:2016/11/29 15:27:00 -- 老师,还是没反应呢 |
||||
-- 作者:有点蓝 -- 发布时间:2016/11/29 15:46:00 -- 这是修改的后台数据。最后你需要重新加载一下数据才会刷新 |
||||
-- 作者:刘林 -- 发布时间:2016/11/29 17:05:00 -- Dim dt As DataTable = DataTables("成绩") Dim Arys As List(Of String()) = dt.GetValues("考试名称|学校代码|年级代码") For Each Ary As String() In Arys Dim drs As List(Of DataRow) = dt.sqlSelect("[考试名称] = \'" & ary(0) & "\'And [学校代码] = \'" & ary(1) & "\'and [年级代码] =\'" & ary(2) & "\'", "折总 DESC") For n As Integer = 0 To drs.Count - 1 \'遍历所有行 If n > 0 AndAlso drs(n)("折总") = drs(n-1)("折总") Then \'如果总分和上一行相同 drs(n)("校序") = drs(n-1)("校序") \'则排名等于上一行 Else drs(n)("校序") = n + 1 \'设置排名 End If Next Next Dim Arys1 As List(Of String()) = dt.GetValues("考试名称|学校代码|年级代码|班级") For Each Ary1 As String() In Arys1 Dim drs As List(Of DataRow) = dt.sqlSelect("[考试名称] = \'" & ary1(0) & "\'And [学校代码] = \'" & ary1(1) & "\'and [年级代码] =\'" & ary1(2) & "\'And [班级] = \'" & ary1(3) & "\'", "折总 DESC") For m As Integer = 0 To drs.Count - 1 \'遍历所有行 If m > 0 AndAlso drs(m)("折总") = drs(m-1)("折总") Then \'如果总分和上一行相同 drs(m)("班序") = drs(m-1)("班序") \'则排名等于上一行 Else drs(m)("班序") = m + 1 \'设置排名 End If Next Next dt.save() 老师我测了,重新加载也没排起 |
||||
-- 作者:有点蓝 -- 发布时间:2016/11/29 17:24:00 -- 唉,都说了用了SQLCommand就没有必要用sqlSelect了 Dim cmd As New SQLCommand Dim dt As DataTable cmd.c cmd.CommandText = "SELeCT * From {成绩}" dt = cmd.ExecuteReader() \'\'Dim dt As DataTable = DataTables("成绩") Dim Arys As List(Of String()) = dt.GetValues("考试名称|学校代码|年级代码") For Each Ary As String() In Arys Dim drs As List(Of DataRow) = dt.Select("[考试名称] = \'" & ary(0) & "\'And [学校代码] = \'" & ary(1) & "\'and [年级代码] =\'" & ary(2) & "\'", "折总 DESC") For n As Integer = 0 To drs.Count - 1 \'遍历所有行 If n > 0 AndAlso drs(n)("折总") = drs(n-1)("折总") Then \'如果总分和上一行相同 drs(n)("校序") = drs(n-1)("校序") \'则排名等于上一行 Else drs(n)("校序") = n + 1 \'设置排名 End If Next Next Dim Arys1 As List(Of String()) = dt.GetValues("考试名称|学校代码|年级代码|班级") For Each Ary1 As String() In Arys1 Dim drs As List(Of DataRow) = dt.Select("[考试名称] = \'" & ary1(0) & "\'And [学校代码] = \'" & ary1(1) & "\'and [年级代码] =\'" & ary1(2) & "\'And [班级] = \'" & ary1(3) & "\'", "折总 DESC") For m As Integer = 0 To drs.Count - 1 \'遍历所有行 If m > 0 AndAlso drs(m)("折总") = drs(m-1)("折总") Then \'如果总分和上一行相同 drs(m)("班序") = drs(m-1)("班序") \'则排名等于上一行 Else drs(m)("班序") = m + 1 \'设置排名 End If Next Next dt.save() DataTables("成绩").load
|
||||
-- 作者:刘林 -- 发布时间:2016/11/29 19:59:00 -- 老师,各种都测了不行,请老师帮看下如何实现在不加载数据情况下也可在后台排序,另外保存速度很慢是什么原因。 |
||||
-- 作者:刘林 -- 发布时间:2016/11/29 20:00:00 --
|
||||
-- 作者:刘林 -- 发布时间:2016/11/29 20:27:00 -- dt = cmd.ExecuteReader(true) 老师,发现了,加个true,现在的问题是排序太久了,5000多条记录花了几分钟,请问如何提高速度
|