Monday, February 20, 2012

RecordCount -1

Hello,
I am using the function below to get some values form database.
However for RecordCount it always returns -1.
Any clues hot to fix it?
Thx
YuriW
Function RunSQL (sConnection_String, sSQL_QUERY)
Dim db_object
Dim sSQL_string
'connection_string = "DSN=Magnetic;UID=laurel;PWD=uklever"
sSQL_string = sSQL_QUERY
' Create the conection object.
Set db_object = CreateObject("ADODB.Connection")
' or use this method if a DSN entry was created.
db_object.Open(sConnection_String)
' Get the recordset returned from a select query.
Set recordset = db_object.Execute(sSQL_string)
' Display the results of the query.
sOut = recordset.RecordCount
RunSQL = sOut
' Close the database connection.
db_object.Close
Set db_object = Nothing
End Function
http://www.aspfaq.com/2193
http://www.aspfaq.com/
(Reverse address to reply.)
"Yuri Weinstein (HotMail)" <yuriw_NOSPAM@.hotmail.com> wrote in message
news:7Mnxc.68469$yx3.34214@.newssvr29.news.prodigy. com...
Hello,
I am using the function below to get some values form database.
However for RecordCount it always returns -1.
Any clues hot to fix it?
Thx
YuriW
Function RunSQL (sConnection_String, sSQL_QUERY)
Dim db_object
Dim sSQL_string
'connection_string = "DSN=Magnetic;UID=laurel;PWD=uklever"
sSQL_string = sSQL_QUERY
' Create the conection object.
Set db_object = CreateObject("ADODB.Connection")
' or use this method if a DSN entry was created.
db_object.Open(sConnection_String)
' Get the recordset returned from a select query.
Set recordset = db_object.Execute(sSQL_string)
' Display the results of the query.
sOut = recordset.RecordCount
RunSQL = sOut
' Close the database connection.
db_object.Close
Set db_object = Nothing
End Function
|||Thanks you. I am still not clear how to change the code in order to fix it?
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:eyU6tjYTEHA.3580@.TK2MSFTNGP09.phx.gbl...
> http://www.aspfaq.com/2193
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "Yuri Weinstein (HotMail)" <yuriw_NOSPAM@.hotmail.com> wrote in message
> news:7Mnxc.68469$yx3.34214@.newssvr29.news.prodigy. com...
> Hello,
> I am using the function below to get some values form database.
> However for RecordCount it always returns -1.
> Any clues hot to fix it?
> Thx
> YuriW
> Function RunSQL (sConnection_String, sSQL_QUERY)
> Dim db_object
> Dim sSQL_string
> 'connection_string = "DSN=Magnetic;UID=laurel;PWD=uklever"
> sSQL_string = sSQL_QUERY
> ' Create the conection object.
> Set db_object = CreateObject("ADODB.Connection")
> ' or use this method if a DSN entry was created.
> db_object.Open(sConnection_String)
> ' Get the recordset returned from a select query.
> Set recordset = db_object.Execute(sSQL_string)
> ' Display the results of the query.
> sOut = recordset.RecordCount
> RunSQL = sOut
> ' Close the database connection.
> db_object.Close
> Set db_object = Nothing
> End Function
>
|||Maybe you need to look at the article again?
http://www.aspfaq.com/
(Reverse address to reply.)
"Yuri Weinstein (HotMail)" <yuriw_NOSPAM@.hotmail.com> wrote in message
news:dnoxc.68491$iR3.59055@.newssvr29.news.prodigy. com...
> Thanks you. I am still not clear how to change the code in order to fix
it?
>
> "Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> news:eyU6tjYTEHA.3580@.TK2MSFTNGP09.phx.gbl...
>
|||Recordcount is not supported with the default forward-only cursor. You can try to set the type of cursor before you excute your SQL code.
"Yuri Weinstein (HotMail)" <yuriw_NOSPAM@.hotmail.com> wrote in message news:7Mnxc.68469$yx3.34214@.newssvr29.news.prodigy. com...
Hello,
I am using the function below to get some values form database.
However for RecordCount it always returns -1.
Any clues hot to fix it?
Thx
YuriW
Function RunSQL (sConnection_String, sSQL_QUERY)
Dim db_object
Dim sSQL_string
'connection_string = "DSN=Magnetic;UID=laurel;PWD=uklever"
sSQL_string = sSQL_QUERY
' Create the conection object.
Set db_object = CreateObject("ADODB.Connection")
' or use this method if a DSN entry was created.
db_object.Open(sConnection_String)
' Get the recordset returned from a select query.
Set recordset = db_object.Execute(sSQL_string)
' Display the results of the query.
sOut = recordset.RecordCount
RunSQL = sOut
' Close the database connection.
db_object.Close
Set db_object = Nothing
End Function
|||Got it, thx!
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:eyU6tjYTEHA.3580@.TK2MSFTNGP09.phx.gbl...
> http://www.aspfaq.com/2193
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "Yuri Weinstein (HotMail)" <yuriw_NOSPAM@.hotmail.com> wrote in message
> news:7Mnxc.68469$yx3.34214@.newssvr29.news.prodigy. com...
> Hello,
> I am using the function below to get some values form database.
> However for RecordCount it always returns -1.
> Any clues hot to fix it?
> Thx
> YuriW
> Function RunSQL (sConnection_String, sSQL_QUERY)
> Dim db_object
> Dim sSQL_string
> 'connection_string = "DSN=Magnetic;UID=laurel;PWD=uklever"
> sSQL_string = sSQL_QUERY
> ' Create the conection object.
> Set db_object = CreateObject("ADODB.Connection")
> ' or use this method if a DSN entry was created.
> db_object.Open(sConnection_String)
> ' Get the recordset returned from a select query.
> Set recordset = db_object.Execute(sSQL_string)
> ' Display the results of the query.
> sOut = recordset.RecordCount
> RunSQL = sOut
> ' Close the database connection.
> db_object.Close
> Set db_object = Nothing
> End Function
>
|||In "Display the results of the query" you should iterate through recordset
with MoveFirst/MoveNext. Add counter into this cycle
dim counter
counter = 0
rs.MoveFirst
while not rs.EOF
... display record
counter = counter + 1
rs.MoveNext
wend
'here counter contains number of records
//--
Regards,
Vassiliev V. V.
http://www-sharp.com -
Scripting/HTA/.Net Framework IDE
"Yuri Weinstein (HotMail)" <yuriw_NOSPAM@.hotmail.com> ??/?? ?
?? ??: news:7Mnxc.68469$yx3.34214@.newssvr29.news.prodigy. com...
Hello,
I am using the function below to get some values form database.
However for RecordCount it always returns -1.
Any clues hot to fix it?
Thx
YuriW
Function RunSQL (sConnection_String, sSQL_QUERY)
Dim db_object
Dim sSQL_string
'connection_string = "DSN=Magnetic;UID=laurel;PWD=uklever"
sSQL_string = sSQL_QUERY
' Create the conection object.
Set db_object = CreateObject("ADODB.Connection")
' or use this method if a DSN entry was created.
db_object.Open(sConnection_String)
' Get the recordset returned from a select query.
Set recordset = db_object.Execute(sSQL_string)
' Display the results of the query.
sOut = recordset.RecordCount
RunSQL = sOut
' Close the database connection.
db_object.Close
Set db_object = Nothing
End Function

No comments:

Post a Comment