简体   繁体   English

如果未传递参数,如何避免vb.net中的请求查询字符串异常

[英]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

You can check what @Massimiliano has reported and one more check 您可以检查@Massimiliano报告了什么,并再检查一次

If Request.QueryString.HasKeys() Then

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

End If
If Not String.IsNullOrEmpty(Request.QueryString("projectStartDate")) Then
    //
End If

如果没有Request.QueryString(“ projectStartDate”)和Request.QueryString(“ projectStartDate”)<>“”然后

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM