I m using the following code to save the date from a textbox and selecting the date using date picker.
If (String.IsNullOrEmpty(DobTxt.Text)) Then
SQLCmd.Parameters.Add("@DOB", SqlDbType.Date).Value = DBNull.Value
Else
Dim DOBDte As date= String.Format("{0:YYYY-MM-dd}", DobTxt.Text.Trim())
SQLCmd.Parameters.Add("@DOB", SqlDbType.Date).Value = DOBDte
End If
Now the code works just fine with dates like ""
but when you go for a date like "10/01/2016" I get this error:
Conversion from string "10/30/2016" to type 'Date' is not valid
could you please help