Hai guys
when i am trying to fetch the data from gridview to textboxes by using the following code iam getting an error like"string was not recognized as a valid datetime"
DtpExpence.Value = Convert.ToDateTime(dgvCompanyExpences.SelectedRows[0].Cells[2].Value.ToString());
Please Help Anyone,Thanks in advance
Its very urgent..
Loading

Jignesh TrivediPosted Jun 25, 2012, 11:30 PM
use DateTime.TryParseExact to convert string to datetime.
try..
string date = dgvCompanyExpences.SelectedRows[0].Cells[2].Value.ToString(); //"06/26/2012";
DateTime d;
CultureInfo enUS = new CultureInfo("en-US");
bool f = DateTime.TryParseExact(date, "MM/dd/yyyy", enUS, DateTimeStyles.None, out d);
In variable "d" you can get Converted DateTime.
hope this will help you.
divyaPosted Jun 26, 2012, 12:02 AM
I got the solution,thank u
your post saved me a bunch of time..
divyaPosted Jun 25, 2012, 11:08 PM
still iam getting the same problem,In database date is defined as datetime datatype..
Mahesh ChandPosted Jun 25, 2012, 10:32 PM
Something like this
string str = dgvCompanyExpences.SelectedRows[0].Cells[2].Value.ToString();
Debug this and see if str looks like a string. This is the problem.