5
Answers

String was not recognized as a valid DateTime.

Nitol Biswas

Nitol Biswas

7y
265
1
This is my code
 
  1. protected void btnUpdate_Click(object sender, EventArgs e)  
  2. {  
  3.         DateTime admissionDate = DateTime.ParseExact(txtAddmissionDate.Text, "dd/MM/yyy         y",  CultureInfo.InvariantCulture);  
  4.         DateTime examDate = DateTime.ParseExact(txtExamDate.Text, "dd/MM/yyyy", Culture        Info.InvariantCulture);  
  5.         DateTime certificateDate = DateTime.ParseExact(txtCertificateDate.Text, "dd/MM/        yyyy", CultureInfo.InvariantCulture);  
  6.   
  7.         SqlConnection cs = new SqlConnection(ConfigurationManager.ConnectionStrings["tr         avelConnectionString"].ConnectionString);  
  8.         String str = "UPDATE [tbl_training_details] SET [service_agent_id] = '" + ddlServiceAgentList.SelectedValue + "',[training_addmission_date] = '" + admissionDate + "',[training_exam_date] = '" + examDate + "',[training_certificate_no] = '" + txtCertificateNo.Text + "',[training_certificate_date] = '" + certificateDate + "',[status_id] = '" + ddlStatus.SelectedValue + "',[comment] = '" + txtComment.Text + "'WHERE [passenger_id] = " + txtPassengerName.Text;  
  9.         SqlCommand sc = new SqlCommand(str, cs);  
  10.         cs.Open();  
  11.         sc.ExecuteNonQuery();  
  12.         cs.Close();  
  13. }  
 
When I click update button "String was not recognized as a valid DateTime." Error Happen. How Should Fix the problem. Please help.
 
 Thanks 
Answers (5)