I have a search page, which has Date text field. The user may or may not populate this field. But the field is a parameter of a SQL stored proc that gets called to execute the search query.
When I walk through the code (and the Date field is blank), I get an error that the value could not be converted to DateTime
How can I convert a null value to DateTime, since the parameter is expected by the query?
cmdSearch.Parameters.Add(new SqlParameter("@StartDate", SqlDbType.DateTime));
cmdSearch.Parameters["@StartDate"].Value = Convert.ToDateTime(txtStartDate.Text.Trim());