Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Unable to get random generation with OleDb
Message
From
18/09/2006 11:10:49
 
 
To
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:
01154711
Views:
10
Hi,

>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()
Don't close the connection here. Let the dataadapter use the same connection (and thus same environment)
>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
>
Since the connection is open when the .Fill is called the dataadapter will leave the connection open and you will need to close it yourself afterwards

HTH,
Viv
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform