czy版主的附件好像抽取出来每组多一人!
这样呢?
Dim bjs As List(Of String) = DataTables("表A").GetUniqueValues("","班级") Dim cnt As Integer = e.Form.Controls("Number").Value-1 'DataTables("表A").StopRedraw() DataTables("表A").DataCols.Add("随机数",GetType(Integer)) For Each dr As Datarow In DataTables("表A").DataRows dr("随机数") = Rand.Next() Next Tables("抽样").DataTable.DataRows.Clear() Tables("表A").Sort = "随机数" For Each bj As String In bjs Tables("表A").Filter = "班级 = '" & bj & "'" For i As integer = 0 To Math.Min(cnt,Tables("表A").Rows.Count) dim r As Row = Tables("抽样").AddNew() r("班级") = Tables("表A").Rows(i)("班级") r("姓名") = Tables("表A").Rows(i)("姓名") Next Next DataTables("表A").DataCols.Delete("随机数") DataTables("表A").ResumeRedraw() Maintable = Tables("抽样")
|