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
Aamir KhanPosted Jun 19, 2012, 5:48 AM
Aamir KhanPosted Jun 19, 2012, 4:28 AM
Kunal VaishyaPosted Jun 19, 2012, 4:12 AM
Suthish NairPosted Jun 19, 2012, 3:57 AM
Jignesh TrivediPosted Jun 19, 2012, 3:52 AM
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.