[英]How to avoid exception of request querystring in vb.net if parameter is not passed
如果未傳遞參數變量,則此代碼將引發異常“從字符串“”轉換為“日期”類型無效”。
這是我的代碼。
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
您可以檢查@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.