PDA

View Full Version : Return NULL from function


hkucsis
03-29-2004, 04:40 AM
Hi,

I have a function that performs login by calling a stored procedure. I want it to return "NULL" if there is error in the stored procedure, return a recordset if no error.


<%
function Login()
...
Set myRecordset = cmd.Execute(...)

If (There is Error in stored proc) Then 'check output parameter of the stored proc
Set Login = Nothing
Else
Set Login = myRecordset
End If
End function


set rsLoginResult = Login()
If Not (IsNull(rsLoginResult)) Then 'Problem here: always is not null
If Not rsLoginResult.EOF then
Response.Write "Logged in"
Else
Response.Write "Failed"
End If
Else
Response.Write "Error in stored procedure"
end if
%>


But rsLoginResult always is NOT null. How to achieve what I want?

Many thanks.

Michael

glenngv
03-29-2004, 05:21 AM
Try:

If Not (rsLoginResult is Nothing) Then


BTW, how do you check for errors in stored proc?

If (There is Error in stored proc) Then

glenngv
03-29-2004, 05:26 AM
If you just want to know if login is successful or not and don't need other properties of the returned recordset, then why don't you just return true or false to the function?

hkucsis
03-29-2004, 05:42 AM
If Not (rsLoginResult is Nothing) Then

is exactly what I am looking for :thumbsup:. Million thanks. :)

>> BTW, how do you check for errors in stored proc?

I will pass an output parameter in the stored proc. If there is error in the stored proc (check @@error), I will assign this output parameter some value.

>> If you just want to know if login is successful or not and don't need other properties of the returned recordset, then why don't you just return true or false to the function?

You are right, but I need some other fields in the table, so I need to return a recordset.

whammy
03-29-2004, 05:52 AM
Hey I have never seen Is Nothing... :|
Have any documentation on it? :eek: :eek:

glenngv
03-29-2004, 06:00 AM
Is operator (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsopris.asp)

Might as well add the difference of Null to Nothing (http://www.w3schools.com/vbscript/vbscript_ref_keywords.asp) and to other similar keywords.

whammy
03-29-2004, 06:03 AM
Well I know that... I have never seen the Is operator used in this context, however... I'll have to do some tests tomorrow.

oracleguy
03-29-2004, 07:08 PM
Hey I have never seen Is Nothing... :|
Have any documentation on it? :eek: :eek:

Yeah it can also come in handy making sure objects haven't been released or that matter created.