G
GS
the procedure when executed from c#, it does update or insert but
I got result code of -1 return to c#
is not successful execution of stored proc 0 or number rows affected?
connectionString ="....whatever";
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
SqlCommand command = connection.CreateCommand();
command.CommandText = " SPPersonSavedbo @personName = 'test 1'
wkStatus = '1', @comment='test comment1', @misc = 'whatever';"
iRows = command.ExecuteNonQuery();
// I got iRows = -1
why?
I got result code of -1 return to c#
ALTER PROCEDURE dbo.SPPersonSave
(
@personName varchar(16),
@wkStatus int,
@comment varchar(512),
@misc varchar(1024),
@mode int /*1 insert only, 2 update only, 3 insert or update as required
depending on key */
)
/* @Result int out 1 as success, - some number of record out there
with the same exist already - should not happen
0 failed to insert
*/
AS BEGIN
SET NOCOUNT ON ;
if ( @mode = 1 or (@mode = 3 and (select count(*) from Regex where
RegexName = @RegexName) < = 0) )
Begin
insert into Person(personName, wkStatus , comment, misc )
values (@personName, wkStatus, @comment, @misc ) ;
/* return status */
End
else if ( @mode = 2 or @mode = 3 )
update Person SET wkStatus = @wkStatus,
comment = @comment, misc = @misc
where personName = @personName;
else if (@mode = 4)
delete from Personwhere personName = @personName ;
else raiserror ('Invalid mode %d of operation for SPPersonSave. Valid: 1
insert, 2 update only, 3 update or insert as required, 4 delete', 1, 1,
@mode);
/* return @Result = @@ERROR ; */
RETURN
END
I got result code of -1 return to c#
is not successful execution of stored proc 0 or number rows affected?
connectionString ="....whatever";
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
SqlCommand command = connection.CreateCommand();
command.CommandText = " SPPersonSavedbo @personName = 'test 1'
wkStatus = '1', @comment='test comment1', @misc = 'whatever';"
iRows = command.ExecuteNonQuery();
// I got iRows = -1
why?
I got result code of -1 return to c#
ALTER PROCEDURE dbo.SPPersonSave
(
@personName varchar(16),
@wkStatus int,
@comment varchar(512),
@misc varchar(1024),
@mode int /*1 insert only, 2 update only, 3 insert or update as required
depending on key */
)
/* @Result int out 1 as success, - some number of record out there
with the same exist already - should not happen
0 failed to insert
*/
AS BEGIN
SET NOCOUNT ON ;
if ( @mode = 1 or (@mode = 3 and (select count(*) from Regex where
RegexName = @RegexName) < = 0) )
Begin
insert into Person(personName, wkStatus , comment, misc )
values (@personName, wkStatus, @comment, @misc ) ;
/* return status */
End
else if ( @mode = 2 or @mode = 3 )
update Person SET wkStatus = @wkStatus,
comment = @comment, misc = @misc
where personName = @personName;
else if (@mode = 4)
delete from Personwhere personName = @personName ;
else raiserror ('Invalid mode %d of operation for SPPersonSave. Valid: 1
insert, 2 update only, 3 update or insert as required, 4 delete', 1, 1,
@mode);
/* return @Result = @@ERROR ; */
RETURN
END