TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Akhter HUssain
719
1.3k
102.3k
String was not recognized as a valid datetime.
Nov 24 2018 8:32 PM
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();
}
Reply
Answers (
8
)
how to create a web form on button in asp net c#
Date get remove when i click row on gridview for editing