当我传递在 Gridview 中选择的值进行删除时,它会抛出 Input String is not in correct format 异常我的代码是,
protected void gridview1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.ToUpper().ToString() == "DELETEREC")
{
try
{
ViewState["id"] = e.CommandArgument.ToString().Trim();
int r = Namespace.SPs.StoredProcedure(Convert.ToInt32(ViewState["id"])).Execute();//Exception thrown Here
if (r > 0)
{
ClientMessaging("Record Deleted Successfully");
Clear();
fillgrid();
}
}
catch (SqlException ex)
{
ClientMessaging(ex.Message);
}
}
}
请帮我解决这个问题
我的 SP 方法是,
public static StoredProcedure StoredProcedure(int id)
{
SubSonic.StoredProcedure sp = new SubSonic.StoredProcedure("StoredProcedure", DataService.GetInstance("TEST"), "");
sp.Command.AddParameter("@Id", id, DbType.Int32);
return sp;
}