When i updating cell date in gridview then it is raising issue of String was not recognized as a valid datetime. In Sql table date column type is datetime.
I am using this code for updating in Gridview
protected void GridView3_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
DateTime date2 = Convert.ToDateTime(txtEntryDate.Text); ///Here is exception is coming///
GridViewRow row = GridView3.Rows[e.RowIndex];
int customerId = Convert.ToInt32(GridView3.DataKeys[e.RowIndex].Values[0]);
string name = (row.FindControl("txtName") as TextBox).Text;
string country = (row.FindControl("txtCountry") as TextBox).Text;
string EntryDate = (row.FindControl("txtEntryDate") as TextBox).Text;
string query = "UPDATE Country SET Name=@Name, Country=@Country, EntryDate=@date2 WHERE CustomerId=@CustomerId";
con = new SqlConnection("Data Source=DESKTOP-5PJ76B9;Integrated Security=SSPI;Initial Catalog=Institute");
{
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Parameters.AddWithValue("@CustomerId", customerId);
cmd.Parameters.AddWithValue("@Name", name);
cmd.Parameters.AddWithValue("@Country", country);
cmd.Parameters.AddWithValue("@date2", EntryDate);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
GridView3.EditIndex = -1;
this.BindGrid();
}


Jignesh KumarRank #91 · 22.9K reputationPosted Nov 24, 2018, 3:56 PM EST
Akhter HUssainRank #1,522 · 1K reputationPosted Nov 24, 2018, 9:29 PM EST
Akhter HUssainRank #1,522 · 1K reputationPosted Nov 24, 2018, 5:58 PM EST
Sanwar RanwaRank #23 · 44.7K reputationPosted Nov 24, 2018, 7:07 PM EST
Akhter HUssainRank #1,522 · 1K reputationPosted Nov 24, 2018, 7:27 PM EST
Jignesh KumarRank #91 · 22.9K reputationPosted Nov 24, 2018, 7:30 PM EST
(txtEntryDate.Text))
Akhter HUssainRank #1,522 · 1K reputationPosted Nov 24, 2018, 7:46 PM EST
Jignesh KumarRank #91 · 22.9K reputationPosted Nov 24, 2018, 7:53 PM EST