473,549 Members | 2,784 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Please help with cmd.execute select SQL?

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.CreateOb ject("ADODB.Con nection")
Set rst = Server.CreateOb ject("ADODB.Rec ordset")
Set cmd = Server.CreateOb ject("ADODB.Com mand")

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.ActiveConne ction = con

Set rst = cmd.Execute(,ar SPrm)


Jul 22 '05 #1
5 5555
Why do you need an ADODB.Command for this?

Please see http://www.aspfaq.com/2126 for a more standard connection string,
and see http://www.aspfaq.com/2193 for workarounds to your recordcount
problem.
On 3/22/05 9:06 PM, in article 3b40e.70832$SF. 2693@lakeread08 , "What-a-Tool"
<Di************ *************@I HateSpam.Com> wrote:
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.CreateOb ject("ADODB.Con nection")
Set rst = Server.CreateOb ject("ADODB.Rec ordset")
Set cmd = Server.CreateOb ject("ADODB.Com mand")

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.ActiveConne ction = con

Set rst = cmd.Execute(,ar SPrm)


Jul 22 '05 #2
www.adopenstatic.com/faq/recordcounterror.asp
http://www.adopenstatic.com/faq/reco...ternatives.asp

Cheers
Ken
"What-a-Tool" <Di************ *************@I HateSpam.Com> wrote in message
news:3b40e.7083 2$SF.2693@laker ead08...
: 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.CreateOb ject("ADODB.Con nection")
: Set rst = Server.CreateOb ject("ADODB.Rec ordset")
: Set cmd = Server.CreateOb ject("ADODB.Com mand")
:
: 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.ActiveConne ction = con
:
: Set rst = cmd.Execute(,ar SPrm)
:
:
:
:
Jul 22 '05 #3
What-a-Tool wrote:
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.CreateOb ject("ADODB.Con nection")
Set rst = Server.CreateOb ject("ADODB.Rec ordset")
Set cmd = Server.CreateOb ject("ADODB.Com mand")

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.ActiveConne ction = con

Set rst = cmd.Execute(,ar SPrm)


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
(adOpenForwardO nly) 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
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #4
Thank you for the advice and the links to the articles. Very helpfull

Sean

Jul 22 '05 #5
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.
Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3478
by: duikboot | last post by:
Hi all, I'm trying to export a view tables from a Oracle database to a Mysql database. I create insert statements (they look alright), but it all goes wrong when I try to execute them in Mysql, because the dates must have quotes on each side. I just don't know how make the dates right. Well I'll just show you the code and some insert...
2
1695
by: chichi | last post by:
Hi there! I was wondering if somebody could tell me how to edit the following ASP code so that the text within the tables appears as Font Color "00FF00". Right now it is appearing in BLACK and since I want the background to be black, it kind of poses a problem. :0 Also, if possible, could you tell me how to change the color of the spaces...
4
2726
by: Max | last post by:
Hello. This is the first time I've posted to a newsgroup, and I do this because I'm in desperate need of help. I'm working a user management system, and when I activate a user that has registered to my system, the current admin user logged in gets logged out. I can't seem to work out how - I can't even trace back where some of the variables...
4
49429
by: gonzal | last post by:
Hi Dose any body know why a temporary table gets deleted after querying it the first time (using SELECT INTO)? When I run the code bellow I'm getting an error message when open the temp table for the second time. Error Type: Microsoft OLE DB Provider for SQL Server (0x80040E37) Invalid object name '#testtable'.
7
8639
by: William Gill | last post by:
I have been trying to pass parameters as indicated in the api. when I use: sql= 'select * from %s where cusid = %s ' % name,recID) Cursor.execute(sql) it works fine, but when I try : sql= 'select * from %s where cusid like %s ' Cursor.execute(sql,(name,recID))
0
1530
by: Edwinah63 | last post by:
Hi guys, i am not new to vb6, but a mere tyro in vb.net what i want to do is the following open transaction build an ADODB command object using parameters execute it build another command execute it
10
1213
by: siasookhteh | last post by:
I also posted this in Django Users group, but figured it probably has more relevance for python group. It seems like a freak problem to me. I spent a long hour to track the problem down and here it is: The following statement fails because it has the '%' sign in it. cursor.execute("select '%'") The error is: IndexError: list index out...
4
3876
by: andy.mcvicker | last post by:
Hi Gang I'm not sure what needs to be changed when converting an asp to vbs. I'm not sure if I can with my code below. Can someone PLEASE convert the text below to vbs? Thanks a million. Andy
4
14107
by: Tonio Tanzi | last post by:
I have the following problem in a Win 2000 Server + SQL Server 2000 environment and I hope somewhat can help me to resolve it (after many days of useless attempts I am desperate). In my database I have two table: - master(id, field1, field2, ...) - detail(id0, id, progr, data, sede, esecutori, brani_autori) in a master-detail relation with...
0
1900
by: bssandeshbs | last post by:
I am developing a Address Book Database Project using Visual Basic 6... When i click the delete button the data does'nt get deleted in the FrontEnd ..But it gets deleted in Database when we see in Access... When i try to delete again in VB front End it gives a Error message and it gets RUN time Error 3021 Either BOF or EOF is true,or...
0
7715
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7956
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7808
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5087
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1935
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.