Hi,
I have a gridview with the column displaying date value. But in DB its datetime datatype.
Label date = (Label)GridView1.Rows[e.RowIndex].FindControl("Date");
In my screen the date value displays like `2014-05-3O` in the grid and in database the value is like `2014-05-30 00:00:00.000`, where I converted datetime to date to show it in the screen. Now I m trying to delete the row and it gives an error. The problem is how can I convert this date to datetime, so that I can pass the string in the delete statement.
Anyone help me with this?
Convert date to datetime c#
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Khan Abrar AhmedRank #778 · 3K reputationPosted Jun 10, 2014, 5:01 AM EDT
Label date = (Label)GridView1.Rows[e.RowIndex].FindControl("Date");
string strdate = Convert.ToDateTime(date.Text).ToString("dd/MMM/yyyy");
Vignesh KumarRank #1,579 · 1K reputationPosted Jun 10, 2014, 5:29 AM EDT
That worked.
I have another column where the datatype is varchar and it has values like 1016, 1023T and when I try to delete I get the error.
Label ID = (Label)GridView1.Rows[e.RowIndex].FindControl("lblID");
Error converting data type varchar to numeric.Khan Abrar AhmedRank #778 · 3K reputationPosted Jun 10, 2014, 6:06 AM EDT
1016, 1023T