以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  符合SQLReplaceFor条件的随机抽取  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=73404)

--  作者:阿福
--  发布时间:2015/8/18 21:41:00
--  符合SQLReplaceFor条件的随机抽取
Dim f1 As String = "[sys_user]=\'" & e.DataRow("sys_user") & "\' and [日龄]>=\'" & e.DataRow("肉猪日龄_低") & "\' and [日龄]<=\'" & e.DataRow("肉猪日龄_高") & "\'"


请问老师,以上符合f1条件的有100条,但我想从里面抽20条数据,实现DataTables("肉猪信息").SQLReplaceFor("栋舍",e.DataRow("原栋舍"),f1)
如何实现?

--  作者:大红袍
--  发布时间:2015/8/18 21:48:00
--  

Dim f1 As String = "[sys_user]=\'" & e.DataRow("sys_user") & "\' and [日龄]>=\'" & e.DataRow("肉猪日龄_低") & "\' and [日龄]<=\'" & e.DataRow("肉猪日龄_高") & "\'"

Dim drs As List(Of DataRow) = DataTables("肉猪信息").sqlselect(f1)
Dim count As Integer = 0
Dim ls As New List(Of Integer)
Do While count < 20
    Dim rnd As Integer = Rand.Next(drs.Count)
    If ls.Contains(rnd) = False Then
        count += 1
        drs(rnd)("栋舍") = e.DataRow("原栋舍")
        drs(rnd).save
    End If
Loop