I am having an issue trying to convert a String to DateTime. I have tried a few things but I keep getting errors thrown up when trying to update the record.
string consentGiven = ConsentGivenDate.Text;
DateTime date1 = Convert.ToDateTime(consentGiven);
cmd.Parameters.Add(new SqlParameter("@ConsentGivenDate", date1));
if ((ConsentGivenDate.Text == "dd/mm/yyyy"))
cmd.Parameters.Add("@ConsentGivenDate", SqlDbType.DateTime).Value = DBNull.Value;
else
cmd.Parameters.Add("@ConsentGivenDate", SqlDbType.DateTime).Value = ConsentGivenDate.Text;
I have tried to add a bit of formatting in so the Date is in British format 'dd/mm/yyyy' but still can't convert it over.
What have I done wrong?
I am a real coding novice so apologies if it is something stupid....