random ข้อมมูลในตาราง โดยให้ค่าที่ออกมาในแต่ละครั้งไม่ซ้ำกันเลย
database access 2003
vb.net
Tag : .NET, Ms Access, VB.NET
Date :
2011-06-01 05:07:57
By :
kang
View :
1465
Reply :
1
No. 1
Guest
Ramdom จาก datatable
Code (VB.NET)
Dim DT1 As New DataTable
DT1.Columns.Add("SN1")
DT1.Columns.Add("NAME1")
DT1.Rows.Add("1", "Test1")
DT1.Rows.Add("2", "Test2")
DT1.Rows.Add("3", "Test3")
DT1.Rows.Add("4", "Test4")
DT1.Rows.Add("5", "Test5")
DT1.Rows.Add("6", "Test6")
DT1.Rows.Add("7", "Test7")
DT1.Rows.Add("8", "Test8")
DT1.Rows.Add("9", "Test9")
DT1.Rows.Add("10", "Test10")
DataGridView1.DataSource = DT1
Dim DT2 As New DataTable
DT2.Columns.Add("SN1")
DT2.Columns.Add("NAME1")
Dim I, CNT, J As Integer
Dim RS As New Random
While DT1.Rows.Count > 0
CNT = DT1.Rows.Count - 1
Try
J = RS.Next(CNT)
DT2.Rows.Add(DT1.Rows(J)("SN1"), DT1.Rows(RS.Next(CNT))("NAME1"))
Catch ex As Exception
End Try
DT1.Rows.RemoveAt(J)
End While
GridView2.DataSource = DT2