v2.0 Select Random Rows from MS Access
(v2.0 Seleccionar filas aleatoriamente en MS Access)
Adding in the query "ORDER BY Rnd(filedName)" or with code
Dim adapter As New OleDbDataAdapter("SELECT * from myTable", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Web.HttpContext.Current.Request.MapPath("data.mdb") + ";")
Dim data As New DataSet
adapter.Fill(data)
Dim table As DataTable = data.Tables(0)
If table.Rows.Count = 0 Then
Throw New Exception("The query return 0 rows")
End If
Dim Random As New Random(System.DateTime.Now.Millisecond)
'first column of the random row
Dim sResult As String = table.Rows(Random.Next(0, table.Rows.Count)).Item(0).ToString()
Thanks Arcadi
Permalink: v2.0 Select Random Rows from MS Access
0 Comments:
Post a Comment
<< Home