Hi.
i have written an insert statement In VS2010 , in one of textbox which is for BirthDate , i have assigned Date type for it in SQlserver 2008r2,
and my code(parameter input) for that field is in below:
cmd.Parameters.Add("@BirthDate_M", SqlDbType.Date).Value = Convert.ToDateTime(BirthDateTextBoxMilad.Text);
whenever i don't write any date inside textbox this exception appears:
String was not recognized as a valid DateTime.
while i want that whenever i don't write anything in textbox , Null to be inserted into the Database, so i wrote this code:
cmd.Parameters.Add("@BirthDate_M", SqlDbType.Date).Value = null;
but if i do this , another exception will appear:
The parameterized query '(@FirstName nvarchar(5),@LastName nvarchar(5),@FatherName nvarch' expects the parameter '@BirthDate_M', which was not supplied.
which indicate that i have to insert a date.how can i prevent this happens and make it insert Null into the database.