[GridView] Deleting last item causes ArgumentOutOfRangeException when using Stored Procedures



I've been scratching my head for quite a few hours over this issue and thought It might be useful if I share my answer.

Turns out if you are using a stored procedure to delete items from the GridView which updates multiple tables or fires triggers this will effect the @@ROWCOUNT value which seems to trip up the rendering of the GridView when deleting the last item.

The fix I settled on was to place a SET NOCOUNT ON at the start of your stored procedure and a SET NOCOUNT OFF at the end.

Regards


MC
.



Relevant Pages

  • Re: Adding date to parameter
    ... ClaimedDate does appear to have a properly formatted date. ... I am using the following stored procedure: ... -- SET NOCOUNT ON added to prevent extra result sets from ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Selecting multiple checkboxes inside a GridView control
    ... Walk through all of the rows in the GridView and construct a comma-delimited string of the IDs of those which are checked. ... Create a stored procedure like below and pass the above string to it: ... DECLARE @strSQL nvarchar ... Rem in the PRINT line and rem out the last two lines if you want to see what the dynamic SQL looks like first for testing purposes. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Procedure or query has too many parameters
    ... I have a gridview and a datasource control. ... I am using stored procedures to select, update, and delete data from the gridview. ... and see the last parameter in the string is not in my update stored procedure, and this string has one more parameter than my update stored procedure has The grid view has more columns that the update proc. ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: Using DTS to Insert 1 Second record for every second in a month?
    ... Okay...so you basically need a calendar table by seconds. ... And yes that will perform pretty fast for the type of query ... >set NoCount OFF ... >This stored procedure took about 21 minutes. ...
    (microsoft.public.sqlserver.dts)
  • RE: Gridview never shows data
    ... not just filtered for the one selected in the first grid. ... I initally just used a select statement in the datasource with an object ... that now to use a stored procedure that takes a string parameter and converts ... where I call DataBind (on both the datasource and the gridview) is correct: ...
    (microsoft.public.dotnet.framework.aspnet)

Loading