6

I'm trying to subclass the .NET 2.0 Gridview control and implement a custom Update to perform when "edit" is clicked; however I get the following cryptic error message: "An unexpected error has occurred." I'm trying to access our db logs to see if its failing there, but until i get access, i cannot debug the issue. Here are snippets of my code:

In the WebPart CreateChildControls method:

sqlDataSource.UpdateCommand = "dbo.UpdateInvoiceData";
sqlDataSource.UpdateCommandType = SqlDataSourceCommandType.StoredProcedure;
sqlDataSource.UpdateParameters.Add(new Parameter("month", DbType.Int32, "2"));
sqlDataSource.UpdateParameters.Add(new Parameter("year", DbType.Int32, "2010"));
this.Controls.Add(sqlDataSource);
EditGridView edv = new EditGridView(sqlDataSource);
this.Controls.Add(edv);

In the EditGridView webcontrol:

OnLoad:

this.AutoGenerateEditButton = true;
this.AutoGenerateColumns = true;
string[] keyNames = { "Name" };
this.DataKeyNames = keyNames;
this.EnableViewState = true;
this.DataSourceID = sqlDataSource.ID;
this.DataBind();

protected override void OnRowUpdating(GridViewUpdateEventArgs e)
{
   try
   {
      sqlDataSource.UpdateParameters.Add(new Parameter("ExtraParamName", DbType.Int32, e.NewValues["ExtraParamName"].ToString()));
      sqlDataSource.UpdateParameters.Add(new Parameter("Name", DbType.String, e.NewValues["Name"].ToString()));
      sqlDataSource.UpdateParameters.Add(new Parameter("spUser", DbType.String, "test"));

    }
    catch (Exception ex)
    {
       this.Page.Response.Write("Error occurred while updating the record.  " + ex.Message);
    }
}
2
  • 11
    Nikkia, in order to figure out what the error is, you can modify the web.config so that instead of the "An unexpected error" page you get a stack trace. See here: blog.thekid.me.uk/archive/2007/02/15/… Commented Mar 11, 2010 at 20:19
  • Can you describe entire problem in more details.? Commented Mar 21, 2011 at 11:24

1 Answer 1

1

This line:

...("ExtraParamName", DbType.Int32, e.NewValues["ExtraParamName"].ToString()));

You are saying the type is an int but you are passing it a string (name). Is that right?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.