tags:

views:

95

answers:

4

I receive the following error when there is no value for querystring. (I mean like index.asp?ID=).

Microsoft VBScript runtime error '800a000d'

Type mismatch: '[string: ""]'

index.asp, line 10

I tried converting NULL value to something else with the following code. It did not work.

MEMBERID        = Request.QueryString("ID")

If MEMBERID = "" or MEMBERID = 0 Then
    MEMBERID = Session("MEMBERID")
End If
+2  A: 

If you want to convert a null to an empty string, use the string concatenation operator &:

MEMBERID = Request.QueryString("ID") & ""
David M
QueryString never returns a null.
AnthonyWJones
A: 

Check for Nothing:

IF Request.QueryString("ID") IS Nothing Then
 ...
End If
Zyphrax
QueryString.Item never returns a null object reference.
AnthonyWJones
+1  A: 

OK, you're getting the parameter ID from the QueryString and checking if it's empty or zero, right? So, you should do something like:

MemberId = Request.QueryString("ID")
'*
'* Check for other than numbers just to be safe
'*
If (MemberId = "" Or Not IsNumeric(MemberId)) Then
   MemberId = Session("MemberId")
End If
'*
'* We can't add this check on the above if because
'* in classic ASP, the expression is evaluated as a whole
'* which would generate an exception when converting to Int
'*
If (CInt(MemberId) = 0) Then
   MemberId = Session("MemberId")
End If
Paulo Santos
A: 

Here is how I would do this:-

 dim memberID : memberID = Request.QueryString("ID")
 if memberID <> "" then memberID = CLng(memberID)
 if memberID = Empty then memberID = Session("MemberID")

The QueryString item property returns either an Empty or a String. It will never return a integer.

If memberID is not parsable as an integer then this code will error. However, if the value on ID is supposed to be an integer but is actually something else then I would want it to fail.

Empty compares as equal to both zero-length string and numeric 0.

AnthonyWJones