I have a gridview and the content data inside gridview is called from a stored procedure,but whenever i want to update the gridview row content an Exception appears.
The update code is as below:
protected void Grid_Updating(object sender, GridViewUpdateEventArgs e)
{
SqlCommand cmd = DataProvider.GenerateCommand("Update_HowzeEducation_SP", CommandType.StoredProcedure);
cmd.Connection.Open();
cmd.Parameters.Add("@FieldName", SqlDbType.NVarChar).Value = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
cmd.Parameters.Add("@DegreeId", SqlDbType.Int).Value = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
cmd.Parameters.Add("@SchoolName", SqlDbType.NVarChar).Value = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
cmd.Parameters.Add("@StudyCityDescribtion", SqlDbType.NVarChar).Value = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text;
cmd.Parameters.Add("@Average", SqlDbType.Decimal).Value = decimal.Parse(((TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0]).Text, CultureInfo.InvariantCulture);
cmd.Parameters.Add("@FinishLevelDate", SqlDbType.Date).Value = Convert.ToDateTime(((TextBox)GridView1.Rows[e.RowIndex].Cells[6].Controls[0]).Text.Trim());
cmd.Parameters.Add("@ThesisTitle", SqlDbType.NVarChar).Value = ((TextBox)GridView1.Rows[e.RowIndex].Cells[7].Controls[0]).Text;
cmd.Parameters.Add("@Describtion", SqlDbType.NVarChar).Value = ((TextBox)GridView1.Rows[e.RowIndex].Cells[8].Controls[0]).Text;
cmd.Parameters.Add("@HowzeEducationId", SqlDbType.Int).Value = GlobalVariables.HowzeEducationId;
cmd.ExecuteNonQuery();
}
And the exception is :
Failed to convert parameter value from a String to a Int32.
This message comes up in the last line of the code.
I will be thankfull for any usefull help.
The error says it all: You are trying to put a string into an int.
See this line:
Could be done as follows
If you have bound the data using a DataSourceID, the NewValues collection would come handy