Insert Stmt returns -1
-
Hi all, I have written an insert query in a Stored Proc, It works fine and inserts an record in the table, but it returns -1 when i execute it thru C# Code. Can anyone tell me why this happens?
Thanks & Regards, Pramod "Everyone is a genius at least once a year"
first paste your stored procedure code here. do you return any thing in your procedure code?
Human knowledge belongs to the world http://www.rad.pasfu.com/index.php
-
first paste your stored procedure code here. do you return any thing in your procedure code?
Human knowledge belongs to the world http://www.rad.pasfu.com/index.php
i dont return any thing from the proc, but the default value returned from an insert proc is 1, in my case donno y it returns -1. I have done some calculations into some variables and a simple insert statement is used to insert the record in the table, I have also used a transaction for this and after the insert statment i have checked if the @intErrorCode is not 0 then rollback transaction, The insert works fine but it returns -1.
Thanks & Regards, Pramod "Everyone is a genius at least once a year"
-
Hi all, I have written an insert query in a Stored Proc, It works fine and inserts an record in the table, but it returns -1 when i execute it thru C# Code. Can anyone tell me why this happens?
Thanks & Regards, Pramod "Everyone is a genius at least once a year"
-
i dont return any thing from the proc, but the default value returned from an insert proc is 1, in my case donno y it returns -1. I have done some calculations into some variables and a simple insert statement is used to insert the record in the table, I have also used a transaction for this and after the insert statment i have checked if the @intErrorCode is not 0 then rollback transaction, The insert works fine but it returns -1.
Thanks & Regards, Pramod "Everyone is a genius at least once a year"
if you call another stored procedure for insert into this procedure? if this is true: call to another procedures into one procedure cause returning -1
Human knowledge belongs to the world http://www.rad.pasfu.com/index.php
-
dbcommand.ExecuteNonQuery();
Thanks & Regards, Pramod "Everyone is a genius at least once a year"
Do you mean
ExecuteNonQuery
returns -1? If yes, see what the documentation says For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. When a trigger exists on a table being inserted or updated, the return value includes the number of rows affected by both the insert or update operation and the number of rows affected by the trigger or triggers. For all other types of statements, the return value is -1. If a rollback occurs, the return value is also -1.Navaneeth How to use google | Ask smart questions
-
Do you mean
ExecuteNonQuery
returns -1? If yes, see what the documentation says For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. When a trigger exists on a table being inserted or updated, the return value includes the number of rows affected by both the insert or update operation and the number of rows affected by the trigger or triggers. For all other types of statements, the return value is -1. If a rollback occurs, the return value is also -1.Navaneeth How to use google | Ask smart questions
yes, tht's a problem, i can the values in the table that means the insert statement was executed, and if an error has occured the insert should be rolledback rite, but this rollback is not happening and m not able to find what the error is. wht r the ways to find the error that has caused the rollback?
Thanks & Regards, Pramod "Everyone is a genius at least once a year"
-
yes, tht's a problem, i can the values in the table that means the insert statement was executed, and if an error has occured the insert should be rolledback rite, but this rollback is not happening and m not able to find what the error is. wht r the ways to find the error that has caused the rollback?
Thanks & Regards, Pramod "Everyone is a genius at least once a year"
-
yes, tht's a problem, i can the values in the table that means the insert statement was executed, and if an error has occured the insert should be rolledback rite, but this rollback is not happening and m not able to find what the error is. wht r the ways to find the error that has caused the rollback?
Thanks & Regards, Pramod "Everyone is a genius at least once a year"
Since you are using Stored procedures, you can handle the errors inside the procedure and rollback if necessary. Add an output parameter which can be used to inform the client program about the process status. Something like,
CREATE PROCEDURE Foo
@FooColumn int = NULL
@ProcessStatus varchar(100) = NULL
AS
// your insert query
IF @@ERROR <>0
BEGIN
ROLLBACK
SET @ProcessStatus = 'Rollbacked'
END
ELSE
BEGIN
SET @ProcessStatus = 'Completed'
ENDNavaneeth How to use google | Ask smart questions
-
Since you are using Stored procedures, you can handle the errors inside the procedure and rollback if necessary. Add an output parameter which can be used to inform the client program about the process status. Something like,
CREATE PROCEDURE Foo
@FooColumn int = NULL
@ProcessStatus varchar(100) = NULL
AS
// your insert query
IF @@ERROR <>0
BEGIN
ROLLBACK
SET @ProcessStatus = 'Rollbacked'
END
ELSE
BEGIN
SET @ProcessStatus = 'Completed'
ENDNavaneeth How to use google | Ask smart questions
Thanks guys for all you suggestions, I found the problem with my stored proc, I had written SET NOCOUNT ON; which was causing the -1 to return. Now i have switched oFF that and it returns me 1.
Thanks & Regards, Pramod "Everyone is a genius at least once a year"