Sir m using using gridview to manage my database record but m getting an error while updating a record on gridview updatecommand m having a column dateposted and oneditcommand the value in shown in textbox but when i am updating the record error shows..this is the error
"System.Data.SqlClient.SqlException: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
The statement has been terminated."
Datatype of date_posted column is datetime in sql.
this is my update command
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string Requirement_Id = Convert.ToString(GridView1.DataKeys[e.RowIndex].Values["Requirement_Id"]);
DropDownList rbtnreqfor = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlreqfor");
string reqfor = Convert.ToString(rbtnreqfor.SelectedItem);
DropDownList PropertyType = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlpropertytype");
string ptype = Convert.ToString(PropertyType.SelectedItem);
DropDownList PropertyAge = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlpropertyage");
string pAge = Convert.ToString(PropertyAge.SelectedItem);
DropDownList City = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlcity");
string city = Convert.ToString(City.SelectedItem.Value);
DropDownList Locality = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddllocality");
string locality = Convert.ToString(Locality.SelectedItem.Value);
DropDownList MinPrice = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlminprice");
string minprice = Convert.ToString(MinPrice.SelectedItem);
DropDownList MaxPrice = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlmaxprice");
string maxprice = Convert.ToString(MaxPrice.SelectedItem);
DropDownList Bedroom = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlbedrooms");
string bedroom = Convert.ToString(Bedroom.SelectedItem);
TextBox Area = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtarea");
string area = Area.Text;
TextBox Features = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtfeatures");
string features = Features.Text;
TextBox Date = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtdate");
DateTime date = DateTime.Parse(Date.Text);
TextBox Name = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtname");
string name = Name.Text;
TextBox Email = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtemail");
string email = Email.Text;
TextBox Mobile = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtmob");
string mobile = Mobile.Text;
CheckBox Active = (CheckBox)GridView1.Rows[e.RowIndex].FindControl("chkactive");
string active = Convert.ToString(Active.Checked);
SqlConnection con = new SqlConnection(str);
string strQ = "update tbl_Post_Requirement set Requirement_For = '"+reqfor+"',Property_Type = '"+ptype+"',Property_Age = '"+pAge+"',City_Id = '"+city+"',Locality_Id='"+locality+"',Min_Price = '"+minprice+"',Max_Price = '"+maxprice+"',Bedrooms='"+bedroom+"',Area='"+area+"',Key_Features='"+features+"',Date_Posted='"+ date +"',Name='"+name+"',Email='"+email+"',Mobile='"+mobile+"', IsActive = '" + active + "' where Requirement_Id='" + Requirement_Id + "'";
SqlCommand cmd = new SqlCommand(strQ, con);
con.Open();
cmd.ExecuteNonQuery();
lblmessage.Text = "Record Updated Successfully";
GridView1.EditIndex = -1;
Filldata();
}