Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
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.
Posted
Comments
MT_ 16-Oct-12 3:18am    
Can you please post the exception you are getting ?

1 solution

cmd.Parameters.Add("@HowzeEducationId", SqlDbType.Int).Value = GlobalVariables.HowzeEducationId; 


There should be your problem. Are you sure that GlobalVariables.HowzeEducationId is an integer?
 
Share this answer
 
Comments
mohammad ehsan 16-Oct-12 3:12am    
Yes i am sure , and this is a class i have written for GlobalVariables.HowzeEducationId as a session to pass the page:
public static int HowzeEducationId
{
get
{
if (HttpContext.Current.Session["HowzeEducationId"] == null)
HttpContext.Current.Session["HowzeEducationId"] = -1;
return int.Parse(HttpContext.Current.Session["HowzeEducationId"].ToString());
}
set
{
HttpContext.Current.Session["HowzeEducationId"] = value;
}
}
Ryan Zahra 16-Oct-12 3:34am    
Could you debug your code and check the returned value of HowzeEducationId?
mohammad ehsan 16-Oct-12 3:45am    
the retuned valued is 15.
Ryan Zahra 16-Oct-12 3:59am    
Are you sure that the database column is set to an integer?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900