themis themis - 6 months ago 12
Vb.net Question

How to avoid exception of request querystring in vb.net 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
Get
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

Answer

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
Comments