Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't get number returned using MAX function

Status
Not open for further replies.

sysr

Technical User
Aug 17, 2001
17
0
0
CA
I am developing an ASP page that is connected to an ACCESS database. I need to get a maximum value for a number field, add 1 to it and use that number as a key value to start the next record.

10 Set Con = Server.CreateObject("ADODB.Connection")
20 Con.Open "accessDSN"

30 sqlInteger="SELECT MAX(OrgID) AS [id] FROM Region"
40 Con.Execute sqlInteger

50 Response.Write(id)
60 id=id+1
70 Response.Write(id)

I can manipulate the database without any problems, so my connection is OK. When I display id on line 50 I get no response, on line 70, I get 1.

There are 5 records in the database and the field is set to be a number. I need to see a number in line 50???

Any help would be greatly appreciated!
 
Yea, because you're not assigning the return value to anything. [id] only exists in the context of the SQL Query, not the ASP page, unless you explicitly assign the resulting dataset to a recordset. Does that make sense? So try this:

Set Con = Server.CreateObject("ADODB.Connection")
Con.Open "accessDSN"

dim rs
set rs = server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = Con

sqlInteger="SELECT MAX(OrgID) AS [id] FROM Region"
rs.open sqlInteger

dim id
id = rs("id")

response.write(id)
id = id + 1
response.write(id)

:)
Paul Prewett
penny.gif
penny.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top