|
-
March 15th, 2004, 01:52 PM
#1
Catching SQL query
Hi
I have a very simple SQL query like this:
strSQL = "select max(fieldname) from tablename"
'Open connection ...
'Excute query...
'Until here everything goes well ...
dim iMax as integer
'Error getting value
iMax = rs.Fields("fieldname").value
But it doesn't work. Anyone any idea?
Greetings,
Jay
-
March 15th, 2004, 02:16 PM
#2
Try this:
iMax = rs("fieldname")
-
March 15th, 2004, 03:53 PM
#3
when using an aggregate function like MAX, even if it does not return an apparant result, it will return a row (in Oracle anyway), so you may be getting the error due to a null value
-
March 15th, 2004, 07:01 PM
#4
iMax = rs.Fields(0).value
the recordset has a filed wich is not "fieldname"
unless you do something like
"select max(fieldname) as TheFieldDescription from tablename"
and only then you could do:
iMax = rs.Fields("TheFieldDescription").value
If table is empty, you should get a record in any case.
Do not know if null or 0 value (cannot test right now)...
If null you can do
iMax = iif(isnull(rs.Fields("TheFieldDescription").value), 0,rs.Fields("TheFieldDescription").value)
Last edited by Cimperiali; March 15th, 2004 at 07:04 PM.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
March 16th, 2004, 03:43 AM
#5
Another thing: integer vs long
You declared iMax as integer.
This means max value should not excede around 32000
If you could get a higher value, then declare it as long.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|