Hello,
I am new to programming. Hope someone can help here.
I am using formview to bind the dtabase to do some manipulations. e.g. edit, insert, delete. In my edit template, I have one textbox bind to a datetime column in the database. I have problem when input null/empty value into the textbox. My code for objectdatasource_inserting statement is here. I use this statement to assign the values from EditTemplate controls to parameters.
Protected Sub CodedValueObjectDataSource_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles CodedValueObjectDataSource.Updating
Dim NewExpriy_date As TextBox = FormView1.FindControl("row_expiry_dateTextBox")
'--------------Dim other controls----------
Dim ExpDate As DateTime
If string.IsNullOrEmpty("NewExpriy_date") 'I also tried NewExpriy_date.text = "" Then
ExpDate = SqlDateTime.Null
'DateTime.MinValue
Else
ExpDate = DateTime.Parse(NewExpriy_date.Text)
'Convert.ToDateTime(NewExpriy_date.Text)
End If
e.InputParameters(
"row_expiry_date") = ExpDate
'Assign values to other parameters
End Sub
When input null/empty in row_expiry_dateTextBox, it seems like my if statement doesn't work and does not read statement ExpDate = SqlDateTime.Null; instead it reads ExpDate = DateTime.Parse(NewExpriy_date.Text) and give me error message "String was not recognized as a valid DateTime." I am wondering what is the value past by the textbox when I left it empty.
BTW, my statement works when I type in a datatime value in the textbox.
thanks in advance.
B.