Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing .NET Gridview with SqlDataSource - on edit exception

Tags:

.net

gridview

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);
    }
}
like image 683
nikkia Avatar asked Mar 11 '10 15:03

nikkia


1 Answers

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?

like image 176
Steve Wellens Avatar answered Sep 29 '22 07:09

Steve Wellens