【问题标题】:How to validate/save date in Asp.Net using VB.NET? [duplicate]如何使用 VB.NET 在 Asp.Net 中验证/保存日期? [复制]
【发布时间】:2017-08-18 10:51:36
【问题描述】:

此代码用于保存日期

If(Not string.IsNullOrEmpty(Datetxt.text)) then
Sqlcmd.Parameters.Add("@dte",SqlDbType.Date)=datetxt.text.trim()
End If

我还必须在代码中添加什么来进行验证?

【问题讨论】:

    标签: vb.net date


    【解决方案1】:

    查看答案here,

    Dim dateValue As Date
    If String.IsNullOrWhiteSpace(DobTxt.Text) Then
        SQLCmd.Parameters.Add("@DOB", SqlDbType.Date).Value = DBNull.Value
    ElseIf Date.TryParse(DobTxt.Text.Trim(), dateValue) Then
        SQLCmd.Parameters.Add("@DOB", SqlDbType.Date).Value = dateValue
    Else
        ' alert the user that there is invalid input
    End If
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-07
      • 1970-01-01
      • 2012-09-04
      相关资源
      最近更新 更多