Hi frnds,
i am getting the following error when i am updating the date in gridview
Error: String was not recognized as a valid DateTime
my code is as follows:
cmd.Parameters.Add("@waiverDate", SqlDbType.DateTime).Value = Convert.ToDateTime(((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1")).Text).ToShortDateString();
Loading

Jignesh TrivediRank #16 · 50.3K reputationPosted Jun 18, 2012, 11:52 PM EDT
Try following code
string date = "12/07/2012";
DateTime d;
CultureInfo enUS = new CultureInfo("en-US");
bool f = DateTime.TryParseExact(date, "dd/MM/yyyy", enUS, DateTimeStyles.None, out d);
cmd.Parameters.AddWithValue("@waiverDate", d);
On base of your culture and format you can parse your date.
hope this will help you.
Suthish NairRank #92 · 22.8K reputationPosted Jun 18, 2012, 11:57 PM EDT
Kunal VaishyaRank #990 · 2K reputationPosted Jun 19, 2012, 12:12 AM EDT
Aamir KhanRank #7,345 · 243 reputationPosted Jun 19, 2012, 12:28 AM EDT
Aamir KhanRank #7,345 · 243 reputationPosted Jun 19, 2012, 1:48 AM EDT