我正在尝试子类化.NET 2.0 Gridview控件并实现自定义更新,以便在单击“编辑”时执行;但是我收到以下神秘错误消息:“发生了意外错误。”我正在尝试访问我们的数据库日志以查看它是否在那里失败,但在我获得访问权限之前,我无法调试该问题。以下是我的代码片段:
在WebPart CreateChildControls方法中:
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);
在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);
}
}
答案 0 :(得分:1)
这一行:
...(“ExtraParamName”,DbType.Int32,e.NewValues [“ExtraParamName”]。ToString()));
你说的是类型是一个int,但你传给它一个字符串(名称)。是吗?