What is the return value of the insert and delete sql statement
-
I read that if I successfully insert one row of data or delete one row of data, the sql server will return me 1. But when I try it, it returns me -1 instead of 1 although the row of data is successfully inserted or deleted. Anyone here could enlighten me if I got something wrong? Thank you very much in advance.
SqlConnection con = new SqlConnection(GUIInitializer.DBconnectionString); SqlCommand cmd = new SqlCommand(GUIInitializer.stp\_GUI\_DELETEITEMAIRLINEMAPPING, con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ITEM\_CODE", itemCode); con.Open(); int rows = cmd.ExecuteNonQuery(); con.Close(); if (rows == -1) { DeleteItemData(itemCode); } else MessageBox.Show("Item Code: " + itemCode + " Deletion FAILED!");
-
I read that if I successfully insert one row of data or delete one row of data, the sql server will return me 1. But when I try it, it returns me -1 instead of 1 although the row of data is successfully inserted or deleted. Anyone here could enlighten me if I got something wrong? Thank you very much in advance.
SqlConnection con = new SqlConnection(GUIInitializer.DBconnectionString); SqlCommand cmd = new SqlCommand(GUIInitializer.stp\_GUI\_DELETEITEMAIRLINEMAPPING, con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ITEM\_CODE", itemCode); con.Open(); int rows = cmd.ExecuteNonQuery(); con.Close(); if (rows == -1) { DeleteItemData(itemCode); } else MessageBox.Show("Item Code: " + itemCode + " Deletion FAILED!");
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.
-
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.
-
Thank you for the reply.. But the above code currently, returns me -1 even though only one row is affected. Is there anything wrong with the code? Thanks again.. :)
I think you should put "SET NOCOUNT ON" in Top of your SP and "SET NOCOUNT OFF" At the end of your SP THANKS
-
I think you should put "SET NOCOUNT ON" in Top of your SP and "SET NOCOUNT OFF" At the end of your SP THANKS
-
I think you should put "SET NOCOUNT ON" in Top of your SP and "SET NOCOUNT OFF" At the end of your SP THANKS
-
ok..got it..sorry for the trouble.. I didn't put the ( ) when I declare the variables in STP.
CREATE PROCEDURE [dbo].[stp_GUI_InsertAirlineData] (
@AIRLINE_CODE varchar(3),
@AIRLINE_DESC nvarchar(50) )Cool!Enjoy! :-D
-
Cool!Enjoy! :-D