473,574 Members | 3,176 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to handle, when SQL command returns a single value

Hi,

I have a problem in dealing with the return value of the SQL command. I know how to do, when SQL command returns Recordsets. But in my case it returns a single value. The following code fails when "objRst.ope n strQ" is executed. Can somebody suggest me how to overcome this problem.

Any Help is appreciated.
Thanks in advance,
Vasanth
-----------------------
Set objConnect = Server.CreateOb ject("ADODB.Con nection")
objConnect.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & mdbFilePath & ";"
Set objRst = Server.CreateOb ject("ADODB.Rec ordset")
strQ = "Select MAX(index) from library where index like '*B-*';"
objRst.Open strQ
cmd.execute
while Not objRst.EOF
index=objRst("i ndex")
objrst.movenext
Wend
Set objRst = nothing
objConnect.Clos e
Set objConnect = nothing
%>
<html>
<head>
<title>
</title>
</head>
<body>
<form action="newupda te.asp" method=post>
index:<%=index% >
</form>
</body>
</html>
----------------------------------------
I also tried the following alternative. Here it fails when I try to print "objRst" on the page.
Set objConnect = Server.CreateOb ject("ADODB.Con nection")
objConnect.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & mdbFilePath & ";"
Set cmd = Server.CreateOb ject("ADODB.Com mand")
Set cmd.ActiveConne ction = objConnect
strQ = "Select MAX(index) from library where index like '*B-*';"
cmd.commandtext =strQ
set objRst = cmd.execute
objConnect.Clos e
Set objConnect = nothing
%>
<html>
<head>
<title>
</title>
</head>
<body>
<form action="newupda te.asp" method=post>
index:<%=objRst %>
</form>
</body>
</html>
Jul 19 '05 #1
2 2296
The problem is that you do not have a column named INDEX in your recordset.
You have an unnamed column that represents MAX(index). You can either name
it in your query or use the index value in the recordset to get it. (Not
the same "index" as in your column name.)

"Select MAX(index) as TheMax from library..."
index = objRst.Fields.I tem("TheMax").V alue

Or, leave your query as is and do:

index = objRst.Fields.I tem(0).Value

Ray at work

"vasanth kumar" <va***********@ eds.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hi,

I have a problem in dealing with the return value of the SQL command. I
know how to do, when SQL command returns Recordsets. But in my case it
returns a single value. The following code fails when "objRst.ope n strQ" is
executed. Can somebody suggest me how to overcome this problem.

Any Help is appreciated.
Thanks in advance,
Vasanth
-----------------------
Set objConnect = Server.CreateOb ject("ADODB.Con nection")
objConnect.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" &
mdbFilePath & ";"
Set objRst = Server.CreateOb ject("ADODB.Rec ordset")
strQ = "Select MAX(index) from library where index like '*B-*';"
objRst.Open strQ
cmd.execute
while Not objRst.EOF
index=objRst("i ndex")
objrst.movenext
Wend
Jul 19 '05 #2
Thanks for the help. It worked.

-Vasanth
"Ray at <%=sLocation% > [MVP]" <myfirstname at lane34 dot com> wrote in
message news:OH******** *****@TK2MSFTNG P12.phx.gbl...
The problem is that you do not have a column named INDEX in your recordset. You have an unnamed column that represents MAX(index). You can either name it in your query or use the index value in the recordset to get it. (Not
the same "index" as in your column name.)

"Select MAX(index) as TheMax from library..."
index = objRst.Fields.I tem("TheMax").V alue

Or, leave your query as is and do:

index = objRst.Fields.I tem(0).Value

Ray at work

"vasanth kumar" <va***********@ eds.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hi,

I have a problem in dealing with the return value of the SQL command. I know how to do, when SQL command returns Recordsets. But in my case it
returns a single value. The following code fails when "objRst.ope n strQ" is executed. Can somebody suggest me how to overcome this problem.

Any Help is appreciated.
Thanks in advance,
Vasanth
-----------------------
Set objConnect = Server.CreateOb ject("ADODB.Con nection")
objConnect.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" &
mdbFilePath & ";"
Set objRst = Server.CreateOb ject("ADODB.Rec ordset")
strQ = "Select MAX(index) from library where index like '*B-*';"
objRst.Open strQ
cmd.execute
while Not objRst.EOF
index=objRst("i ndex")
objrst.movenext
Wend

Jul 19 '05 #3

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

Similar topics

0
3538
by: iKiLL | last post by:
Hi All Code Below for this problem ERROR: "An existing connection was forcibly closed by the remote host"
9
3007
by: PengYu.UT | last post by:
Hi, I feel argparse has some useful things that optparse doesn't have. But I can't find it argparse in python library reference. I'm wondering when it will be available in the python standard installation. Thanks, Peng
0
7843
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8111
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
8274
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...
1
7863
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6514
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
5336
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
3776
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...
1
2282
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
1102
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.