以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]代码出错,求助修改(已解决) (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=23693) |
||||
-- 作者:yyzlxc -- 发布时间:2012/9/17 10:40:00 -- [求助]代码出错,求助修改(已解决) 一分厂根据考核分名次排定,二分厂根据一分厂的名次考核分来套取名次。
如何用代码来实现上述要求,请各位老师指教,谢谢!
[此贴子已经被作者于2012-9-17 15:09:12编辑过]
|
||||
-- 作者:lin_hailun -- 发布时间:2012/9/17 11:39:00 -- 代码如下 Dim drs As List(Of DataRow) = DataTables("考核名次").Select("厂家 = \'一分厂\'", "考核分 desc") Dim count As Integer = 1 For Each dr As DataRow In drs dr("名次") = count count = count + 1 Next Dim dr3 As DataRow = DataTables("考核名次").Find("名次 = 3 And 厂家 = \'一分厂\'") Dim dr5 As DataRow = DataTables("考核名次").Find("名次 = 5 And 厂家 = \'一分厂\'") Dim drMin As DataRow = DataTables("考核名次").Find("名次 = " & count - 1 & " And 厂家 = \'一分厂\'") Dim odrs As List(Of DataRow) = DataTables("考核名次").Select("厂家 = \'一分厂\' And 名次 > 5", "考核分 desc") drs = DataTables("考核名次").Select("厂家 = \'二分厂\'") For Each dr As DataRow In drs If dr("考核分") >= dr3("考核分") Then dr("名次") = 3 Else If dr("考核分") >= dr5("考核分") Then dr("名次") = 5 Else If dr("考核分") >= drMin("考核分") Then For Each odr As DataRow In odrs If dr("考核分") >= odr("考核分") Then dr("名次") = odr("名次") Exit For End If Next Else dr("名次") = count - 1 End If Next |
||||
-- 作者:yyzlxc -- 发布时间:2012/9/17 11:53:00 -- 谢谢lin_hailun老师的回复,代码运行出错,提示如图:
![]() ![]() |
||||
-- 作者:yyzlxc -- 发布时间:2012/9/17 12:54:00 -- [求助]代码出错,求助修改
Dim drs As List(Of DataRow) = DataTables("考核名次").Select("厂家 = \'一分厂\'", "考核分 desc") For Each dr As DataRow In drs
将变量count的初始值改成 "0",代码可以通过,但是名次提升了一档。
如果再将代码"dr("名次") = count "改成"dr("名次") = count + 1 ",名次符合要求,但是出现出错提示:
如何修改代码,请各位老师指教,谢谢!!
再次感谢lin_hailun老师!! [此贴子已经被作者于2012-9-17 12:56:36编辑过]
|
||||
-- 作者:lin_hailun -- 发布时间:2012/9/17 14:23:00 -- 哦哦,忘记你第一行是空值了。 Dim drs As List(Of DataRow) = DataTables("考核名次").Select("厂家 = \'一分厂\'", "考核分 desc") Dim count As Integer = 1 For Each dr As DataRow In drs dr("名次") = count count = count + 1 Next Dim dr3 As DataRow = DataTables("考核名次").Find("名次 = \'3\' And 厂家 = \'一分厂\'") Dim dr5 As DataRow = DataTables("考核名次").Find("名次 = \'5\' And 厂家 = \'一分厂\'") Dim drMin As DataRow = DataTables("考核名次").Find("名次 = \'" & count - 1 & "\' And 厂家 = \'一分厂\'") Dim odrs As List(Of DataRow) = DataTables("考核名次").Select("厂家 = \'一分厂\' And 名次 > 5", "考核分 desc") drs = DataTables("考核名次").Select("厂家 = \'二分厂\'") For Each dr As DataRow In drs If dr("考核分") >= dr3("考核分") Then dr("名次") = 3 Else If dr("考核分") >= dr5("考核分") Then dr("名次") = 5 Else If dr("考核分") >= drMin("考核分") Then For Each odr As DataRow In odrs If dr("考核分") >= odr("考核分") Then dr("名次") = odr("名次") Exit For End If Next Else If dr("厂家") <> "" Then dr("名次") = count - 1 End If Next |
||||
-- 作者:yyzlxc -- 发布时间:2012/9/17 15:09:00 -- 谢谢lin_hailun老师的回复,问题解决了,再次衷心感谢!! |