Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Unable to get random generation with OleDb
Message
From
18/09/2006 10:41:56
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01154512
Message ID:
01154692
Views:
11
>Don't think that's true - it *is* true for each connection so you should be able to do something like:
>.CommandText = "RAND(-1)"
>.ExecuteNonQuery()
>.CommandText = "SELECT TOP 10 RAND()....."
>.Fill(...)
Just so you could try it by yourself, here is the code sample I tried with.
Dim oCommand As IDbCommand = Nothing
Dim oConnection As IDbConnection = Nothing
Dim oDataAdapter As IDbDataAdapter = Nothing
Dim oDataSet As DataSet
Dim oDataView As DataView
oConnection = New OleDbConnection(oApp.aConnection(1))
oDataAdapter = New OleDbDataAdapter
oCommand = New OleDbCommand
oCommand.Connection = oConnection
oCommand.CommandText = "RAND(-1)"
oCommand.Connection.Open()
oCommand.ExecuteNonQuery()
oCommand.Connection.Close()
oCommand.CommandText = "SELECT TOP 10 RAND() AS Test,Video.Date,..."
oDataAdapter.SelectCommand = oCommand
oDataSet = New DataSet
oDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
oDataAdapter.Fill(oDataSet)
oDataSet.Tables("Table").TableName = "Temp"
oDataView = New DataView
oDataView = oDataSet.Tables("Temp").DefaultView
loRow = oDataView(0).Row
This gets 10 records from the SQL. If I print the Test value from loRow, such as loRow("Test"), I will always get the same values for the records such as 0.91, 0.88, 0.79, for the first three records, everytime this code is executed.

At first, I put this RAND(-1) command at the top of my application, where it was only executed once. But, that didn't change anything so I tried to put it at this level and it was the same.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform