Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello sir
I am getting an error "String was not recognized as a valid DateTime." My code is like given below.
C#
private void buttonEdit_Click(object sender, EventArgs e)
{
         Form2 t = new Form2();
         t.Show();
         int i;
         i = dataGridView1.SelectedCells[0].RowIndex;
         t.comboBoxthana.SelectedItem = dataGridView1.Rows[i].Cells[0].Value.ToString();
         t.textBoxLicence_number.Text = dataGridView1.Rows[i].Cells[1].Value.ToString();
         t.dateTimePicker1.Value =DateTime.Parse( dataGridView1.Rows[i].Cells[2].Value.ToString());
}
Posted
Updated 30-Oct-13 1:26am
v2
Comments
Thanks7872 30-Oct-13 7:28am    
What is the format of the date you have in dataGridView1.Rows[i].Cells[2].Value?
Member 10358986 31-Oct-13 1:59am    
"2012-01-01 00:00:00" and "25-Sep-13" for this date my code is working.
"12/28/1951 " for this format its showing the above error.
please solve this.
thank you.

1 solution

The message is clear: you either have a string not representing a valid date (e.g. "foo") or the string itself does not represent a valid date in the 'thread current culture' (see the MSDN page: "DateTime.Parse Method"[^]).
Youd should debug your code for finding out the exact nature of the problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900