themis themis - 4 months ago 9x Question

How to avoid exception of request querystring in if parameter is not passed

If the parameter variable is not passed then this code throws an exception of "Conversion from string "" to type 'Date' is not valid."

this is my code.

Public Shared ReadOnly Property Request_projectStartDate() As Date
Dim _value As String = Nothing

If Not HttpContext.Current.Request.QueryString("projectStartDate") Is Nothing Then
_value = HttpContext.Current.Request.QueryString("projectStartDate").ToString()
End If

Return CDate(_value)
End Get
End Property


You can check what @Massimiliano has reported and one more check

If Request.QueryString.HasKeys() Then

   // Check for specified querystrings...
   If Not String.IsNullOrEmpty(Request.QueryString("projectStartDate")) Then
       // Your logic
   End If

End If