468,554 Members | 1,966 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,554 developers. It's quick & easy.

ExecuteNonQuery returning -1 (vb+asp.net+sqlserver 2000)

In my code I am executing a stored procedure to do a single row insert.
I check the return value of the execution and I am getting -1, whereas
a few weeks ago it was returning 0. Actually, I found that all of my
insert stored procs are returning -1. The stored proc/insert statement
is still executing successfully but the return code is different. If I
execute the procedure from SQL Query Analyzer with the same params, it
shows a return code of 0. But -1 is return back when it is executed
from code. Anyone know why?
FYI - I recently promoted 3 new stored procs; completely unrelated to
this functionality. That is all that has "changed" recently.

Here is some of the code:

nReturn = CInt(cmd.ExecuteNonQuery())

--Stored proc:

Procedure dbo.AddVehicle
/* Param List */
@license varchar(8),
@model_id int,
@year smallint,
@vin varchar(20),
@bar_code varchar(6),
@gas_card varchar(4)

AS
SET NOCOUNT ON

INSERT INTO Vehicles ( license, model_id, [year], vin, bar_code,
gas_card )
VALUES ( @license, @model_id, @year, @vin, @bar_code, @gas_card )

SET NOCOUNT OFF

Aug 9 '06 #1
2 2823
According to the .NET v1.1 documentation...

For UPDATE, INSERT, and DELETE statements, the return value is the number of
rows affected by the command. For all other types of statements, the return
value is -1. If a rollback occurs, the return value is also -1.
--
Brad

"Software is like melted pudding..."
"jz*******@gmail.com" wrote:
In my code I am executing a stored procedure to do a single row insert.
I check the return value of the execution and I am getting -1, whereas
a few weeks ago it was returning 0. Actually, I found that all of my
insert stored procs are returning -1. The stored proc/insert statement
is still executing successfully but the return code is different. If I
execute the procedure from SQL Query Analyzer with the same params, it
shows a return code of 0. But -1 is return back when it is executed
from code. Anyone know why?
FYI - I recently promoted 3 new stored procs; completely unrelated to
this functionality. That is all that has "changed" recently.

Here is some of the code:

nReturn = CInt(cmd.ExecuteNonQuery())

--Stored proc:

Procedure dbo.AddVehicle
/* Param List */
@license varchar(8),
@model_id int,
@year smallint,
@vin varchar(20),
@bar_code varchar(6),
@gas_card varchar(4)

AS
SET NOCOUNT ON

INSERT INTO Vehicles ( license, model_id, [year], vin, bar_code,
gas_card )
VALUES ( @license, @model_id, @year, @vin, @bar_code, @gas_card )

SET NOCOUNT OFF

Aug 9 '06 #2
I confirmed that after the proc was called and -1 was returned, the
record had been inserted.

Aug 9 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by prabhu | last post: by
reply views Thread by Alain \Mbuna\ | last post: by
3 posts views Thread by mokles | last post: by
6 posts views Thread by John | last post: by
2 posts views Thread by XML Beginner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.