hur gör man för att ta ut tio slumpvis valda poster ur en databas? <code>ta ut 10 slumpvis valda poster
Sv: ta ut 10 slumpvis valda poster
Dim con
Dim rsTemp
Dim Index
Dim SubIndex
Dim Records()
Dim Position
Dim RecordCount
Const Count = 10
Const adUseClient = 3
Const adOpenStatic = 3
Const adLockReadOnly = 1
Set con = Server.CreateObject("ADODB.Connection")
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Persist Security Info=False;" & _
"Data Source=G:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB"
Set rsTemp = Server.CreateObject("ADODB.Recordset")
rsTemp.CursorLocation = adUseClient
rsTemp.Open "SELECT * FROM Customers", con, adOpenStatic, adLockReadOnly
Randomize
ReDim Records(Count)
RecordCount = rsTemp.RecordCount
For Index = 1 To Count
Do
Position = Fix(RecordCount * Rnd)
For SubIndex = 1 To Index - 1
If Position = Records(SubIndex) Then
Exit For
End If
Next
Loop Until SubIndex = Index
Records(Index) = Position
rsTemp.AbsolutePosition = Position
'
'Skriv ut post
'
Next
</code>