Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
ExecNonQuery Function from a Business Object
Message
De
27/06/2007 19:30:57
 
 
À
27/06/2007 11:05:30
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01235787
Message ID:
01236170
Vues:
19
> my stored procedure does an insert if the record doesn't exist and update if it does. I really dont want to return a dataset, I just need a rowcount that the record was updated. Somehow ExecNonQuery doesn't work for me.
create procedure UpdateThing( @ThingPK int, @ThingData varchar(20) )
as
   declare @RowCount int;
   update Thing set ThingData = @ThingData where ThingPK = @ThingPK
   set @RowCount = @@ROWCOUNT
   if @RowCount = 0
   begin
      insert into Thing (ThingPK, ThingData) values (@ThingPK,@ThingData)
   set @RowCount = @@ROWCOUNT
   end
   
   select @RowCount as Result;
go
and
object rowcount = this.ExecSprocScalar("UpdateThing", this.CreateParameter("@ThingPK", 4)
                    , this.CreateParameter("@ThingData", "Hello there" ));

if( ! (rowcount is int && (int)rowcount>0) )
{
 throw new Exception("Update failed");
}
ExecNonQuery() won't call a stored procedure by name unless you build the EXEC statement by hand.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform