Thanks James. That's just what I needed. I've never used the ordinal references to column names before, because I've always known the column names. That's cool. I'll probably use that again pretty soon.
I have bad news. I got an error message that says: "Current provider does not support returning multiple recordsets from a single execution." My current provider I guess is ASP 3.0. The message reads as if ASP knows that ADO was sending it two recordsets, but it doesn't know what to do with them. So, I guess I can't use this approach.
What about the idea of using an output parameter?
Here's what I've got so far:
Code:
CREATE PROCEDURE usp_GetInterests
@PersonID int,
@InterestCount int = Null OUTPUT
AS
SELECT @InterestCount = CAST((SELECT COUNT(*) FROM tblInterests WHERE (intID = @PersonID)) AS int)
SELECT intID, intInterestsID
FROM tblInterests
WHERE (intID = @PersonID)
This seems to work, because when I do this in Query Analyzer:
Code:
Declare @Bob int
EXEC usp_GetInterests 20918, @Bob OUTPUT
PRINT @Bob
I get this result:
Code:
intID intInterestsID
------------- ----------------
20918 8
(1 row(s) affected)
1
But when I go to my ASP page and do this:
Code:
Dim rsInterests
Set rsInterests = server.CreateObject("ADODB.Recordset")
With cmd 'A command object created earlier
.ActiveConnection = cnML
.CommandType = adcmdstoredproc
.CommandText = "usp_GetInterests"
.Parameters("@PersonID").Value = strPersonID
.Parameters("@InterestCount").Value = Null
.Parameters("@InterestCount").Direction = adParamOutput
Set rsInterests = .Execute
End With
Dim intInterestCount
intInterestCount = cmd("@InterestCount")
Response.Write intInterestCount
I get nothing. No error message, just nothing. When I change the second to the last line to
Code:
intInterestCount = cmd("@PersonID")
it correctly gives me the person's ID.
Am I doing this wrong? Is there an easier way to get ASP to print an OUTPUT parameter from a SQL stored procedure?
I really appreciate all the help you guys have given me.