• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

ExecuteNonQuery return -1

From my vb net application I call a stored procedure in a Pervasive database. This is the st.proc.
CREATE PROCEDURE "spUpdateAllineaPos18" (in :AllineaPos18 utinyint,
in :Descrizione varchar(50));

BEGIN
      UPDATE AnaAllineaPos18
      SET Descrizione = :Descrizione
      WHERE AllineaPos18 = :AllineaPos18;
END;

To call it I use a PSqlCommand. What is strange is that if I call ExecuteNonQuery the method always return -1 but the stored was executed exactly. Why?
0
fantamen
Asked:
fantamen
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
that is normal, because that procedure does not return any records, ie it does not run a UPDATE, INSERT, DELETE statement directly.
calling a stored procedure will hence return -1. it's not 100% clear in the docs, though:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executenonquery.aspx

if you want the number of rows affected, you have to "return" that in a output parameter, for example.
0
 
fantamenAuthor Commented:
Dear angellll I've modified my stored procedure:
CREATE PROCEDURE "spUpdateAllineaPos18" (in :AllineaPos18 utinyint,
in :Descrizione varchar(50), out :RecUpd integer);

BEGIN
      UPDATE AnaAllineaPos18
      SET Descrizione = :Descrizione
      WHERE AllineaPos18 = :AllineaPos18;
      SET :RecUpd = @@ROWCOUNT;
END;

In vb code I read the output parameter RecUpd and it look to work correctly. What do you think?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>SET :RecUpd = @@ROWCOUNT;
yes, that is exactly the most performant method, AFAIK.
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now