|
 |
asp_databases thread: Seems strange to me...
Message #1 by Ruben Chadien <ruben.chadien@m...> on Thu, 16 Aug 2001 16:37:01 +0200
|
|
Hi,
I got a function that execute an SQL-query and return a disconnected
recordset , but
a don't get a RecordSet object back insteed a get the Fields Collection ,
why ? :-)
Here is the code:
function executeSQLRS(strSQL)
Dim oConn
Dim oRS
Const adOpenStatic = 3
Const adUseClient = 3
Const adLockBatchOptimistic = 4
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open Application("connectionString")
Set oRS = Server.CreateObject("ADODB.Recordset")
oRS.CursorLocation = adUseClient
oRS.Open strSQL, oConn, adOpenStatic, adLockBatchOptimistic
Set oRS.ActiveConnection = Nothing
Set executeSQLRS = oRS
'oConn.Close
'oRS.Close
'Set oConn = Nothing
'Set oRS = Nothing
end function
/TIA Ruben Chadien
Message #2 by Ruben Chadien <ruben.chadien@m...> on Thu, 16 Aug 2001 17:06:21 +0200
|
|
Nevermind, i got it working seem like if you call the function like this:
Set myRST = executeSQLRS(SQL) -You get a RecordSet object back
And if you call it like this:
myRST = executeSQLRS(SQL) -You get a Fields object back
Strange ?
/Ruben Chadien
-----Original Message-----
From: Ruben Chadien [mailto:ruben.chadien@m...]
Sent: den 16 augusti 2001 16:59
To: ASP Databases
Subject: [asp_databases] Seems strange to me...
Hi,
I got a function that execute an SQL-query and return a disconnected
recordset , but
a don't get a RecordSet object back insteed a get the Fields Collection,
why ? :-)
Here is the code:
function executeSQLRS(strSQL)
Dim oConn
Dim oRS
Const adOpenStatic = 3
Const adUseClient = 3
Const adLockBatchOptimistic = 4
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open Application("connectionString")
Set oRS = Server.CreateObject("ADODB.Recordset")
oRS.CursorLocation = adUseClient
oRS.Open strSQL, oConn, adOpenStatic, adLockBatchOptimistic
Set oRS.ActiveConnection =3D Nothing
Set executeSQLRS = oRS
'oConn.Close
'oRS.Close
'Set oConn = Nothing
'Set oRS = Nothing
end function
/TIA Ruben Chadien
Message #3 by Steve Carter <Steve.Carter@t...> on Thu, 16 Aug 2001 16:47:58 +0100
|
|
Yeah, it's that old devil called 'default properties'. The fields
collection is the default property of a recordset, which is why you can go
oRs("MyField") instead of oRs.Fields("MyField").value
Unfortunately it gets a bit counter intuitive from time to time.
I try to be explicit and type it longhand nowadays, just to keep it clear
what's actually being read and written.
> -----Original Message-----
> From: Ruben Chadien [mailto:ruben.chadien@m...]
> Sent: 16 August 2001 16:06
> To: ASP Databases
> Subject: [asp_databases] RE: Seems strange to me...
>
>
> Nevermind, i got it working seem like if you call the function like this:
> Set myRST = executeSQLRS(SQL) -You get a RecordSet object back
> And if you call it like this:
> myRST = executeSQLRS(SQL) -You get a Fields object back
>
> Strange ?
>
> /Ruben Chadien
>
> -----Original Message-----
> From: Ruben Chadien [mailto:ruben.chadien@m...]
> Sent: den 16 augusti 2001 16:59
> To: ASP Databases
> Subject: [asp_databases] Seems strange to me...
>
>
> Hi,
> I got a function that execute an SQL-query and return a disconnected
> recordset , but
> a don't get a RecordSet object back insteed a get the Fields Collection,
> why ? :-)
>
> Here is the code:
>
> function executeSQLRS(strSQL)
> Dim oConn
> Dim oRS
>
> Const adOpenStatic = 3
> Const adUseClient = 3
> Const adLockBatchOptimistic = 4
>
> Set oConn = Server.CreateObject("ADODB.Connection")
> oConn.Open Application("connectionString")
>
> Set oRS = Server.CreateObject("ADODB.Recordset")
> oRS.CursorLocation = adUseClient
> oRS.Open strSQL, oConn, adOpenStatic, adLockBatchOptimistic
>
> Set oRS.ActiveConnection = Nothing
>
> Set executeSQLRS = oRS
>
> 'oConn.Close
> 'oRS.Close
> 'Set oConn = Nothing
> 'Set oRS = Nothing
>
> end function
>
>
> /TIA Ruben Chadien
Message #4 by "Ken Schaefer" <ken@a...> on Fri, 17 Aug 2001 17:23:44 +1000
|
|
When you don't use SET, you are doing a LET
myVar = objConn.Execute(strSQL) is the same as
myVar = objRS is the same as
LET myVar = Object.DefaultProperty.Value
If you want to have your variable reference your object, you need to use SET
Set myVar = objConn.Execute(strSQL)
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----- Original Message -----
From: "Ruben Chadien" <ruben.chadien@m...>
To: "ASP Databases" <asp_databases@p...>
Sent: Friday, August 17, 2001 1:06 AM
Subject: [asp_databases] RE: Seems strange to me...
Nevermind, i got it working seem like if you call the function like this:
Set myRST =xecuteSQLRS(SQL) -You get a RecordSet object back
And if you call it like this:
myRST =xecuteSQLRS(SQL) -You get a Fields object back
Strange ?
/Ruben Chadien
-----Original Message-----
From: Ruben Chadien [mailto:ruben.chadien@m...]
Sent: den 16 augusti 2001 16:59
To: ASP Databases
Subject: [asp_databases] Seems strange to me...
Hi,
I got a function that execute an SQL-query and return a disconnected
recordset , but
a don't get a RecordSet object back insteed a get the Fields Collection,
why ? :-)
Here is the code:
function executeSQLRS(strSQL)
Dim oConn
Dim oRS
|
|
 |