Please help with cmd.execute select SQL?

W

What-a-Tool

What is the proper format for my SQL str using command.execute? Even though
I know I have matching data in my table, I keep coming up with a
..RecordCount of -1. What am I doing wrong?

Thanks in advance :

'Create a connection object
Set con = Server.CreateObject("ADODB.Connection")
Set rst = Server.CreateObject("ADODB.Recordset")
Set cmd = Server.CreateObject("ADODB.Command")

strSQL = "SELECT tblUI.IPAdd FROM tblUI WHERE (tblUI.IPAdd ='?')"
arSPrm = Array(strRemHst)

con.Provider = "Microsoft.Jet.OLEDB.4.0"
con.Open Server.MapPath("../dbs/vstr.mdb")

cmd.CommandType = 1
cmd.CommandText = strSQL
Set cmd.ActiveConnection = con

Set rst = cmd.Execute(,arSPrm)
 
K

Ken Schaefer

www.adopenstatic.com/faq/recordcounterror.asp
www.adopenstatic.com/faq/recordcountalternatives.asp

Cheers
Ken


: What is the proper format for my SQL str using command.execute? Even
though
: I know I have matching data in my table, I keep coming up with a
: .RecordCount of -1. What am I doing wrong?
:
: Thanks in advance :
:
: 'Create a connection object
: Set con = Server.CreateObject("ADODB.Connection")
: Set rst = Server.CreateObject("ADODB.Recordset")
: Set cmd = Server.CreateObject("ADODB.Command")
:
: strSQL = "SELECT tblUI.IPAdd FROM tblUI WHERE (tblUI.IPAdd ='?')"
: arSPrm = Array(strRemHst)
:
: con.Provider = "Microsoft.Jet.OLEDB.4.0"
: con.Open Server.MapPath("../dbs/vstr.mdb")
:
: cmd.CommandType = 1
: cmd.CommandText = strSQL
: Set cmd.ActiveConnection = con
:
: Set rst = cmd.Execute(,arSPrm)
:
:
:
:
 
B

Bob Barrows [MVP]

What-a-Tool said:
What is the proper format for my SQL str using command.execute? Even
though I know I have matching data in my table, I keep coming up with
a .RecordCount of -1. What am I doing wrong?

Thanks in advance :

'Create a connection object
Set con = Server.CreateObject("ADODB.Connection")
Set rst = Server.CreateObject("ADODB.Recordset")
Set cmd = Server.CreateObject("ADODB.Command")

strSQL = "SELECT tblUI.IPAdd FROM tblUI WHERE (tblUI.IPAdd ='?')"
arSPrm = Array(strRemHst)

con.Provider = "Microsoft.Jet.OLEDB.4.0"
con.Open Server.MapPath("../dbs/vstr.mdb")

cmd.CommandType = 1
cmd.CommandText = strSQL
Set cmd.ActiveConnection = con

Set rst = cmd.Execute(,arSPrm)

It's got nothing to do with the use of a Command object. I think Aaron
missed the fact that you are using the Command to pass parameters to your
sql statement when he questioned your use of it.

RecordCount requires the use of an expensive cursor. The default cursor
(adOpenForwardOnly) which your code is usig, is a great, cheap cursor type
which, however, does not support RecordCount. Now some may suggest
specifying a more expensive cursor, either a client-side static cursor, or a
server-side static, keyset, or dynamic cursor. However, there is no need to
do this. Aaron's article makes the good suggestion of using GetRows, which
has several advantages:

1. By getting your data into an array, it allows you to close your recordset
and connection immediately, releasing the connection back to the connection
pool and allowing it to be re-used by the next user instead of requiring a
new connection to be open. Fewer open connections = more scalable
application.
2. Processing the data is more efficient because it can be thousands of
times faster to loop through an array than it is to loop through a recordset
3. It allows you to use Ubound to determine the number of records that were
returned

Bob Barrows
 
W

What-a-Tool

Wnt with this method after reading the post "Do Until Loop problems" replied
to by Bob Barrows and decided to try it

By the way, I ended up using the "GetRows" method suggested in the AspFaq
#2193 - did just what I wanted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top