Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Capture return value from a SP
Message
De
13/12/2005 12:20:53
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
C# 1.1
Database:
MS SQL Server
Divers
Thread ID:
01077504
Message ID:
01077544
Vues:
34
>>>I am having some problems capturing the return value from a SP after I excecute it. Here is the code I use:
>>>
>>>
>>>SqlConnection oCon = new SqlConnection(this.ConnectionString);
>>>SqlCommand cmd = new SqlCommand("mySP", oCon);
>>>cmd.CommandType = CommandType.StoredProcedure;
>>>SqlParameter oParam = cmd.Parameters.Add("@Id", SqlDbType.UniqueIdentifier);
>>>oParam.Value = myID;
>>>oCon.Open();
>>>cmd.ExecuteNonQuery();
>>>oCon.Close();
>>>
>>>
>>>I have been raising exceptions within SPs to notify the client that something was not cosher, but I would also like to know how to evaluate the return value from a SP.
>>>
>>>Let us assume that for this example the SP looks something like this:
>>>
>>>UPDATE myTable SET Name = 'Einar' WHERE Id = @Id
>>>RETURN @@ERROR
>>>
>>
>>Einar,
>>I don't know if I posted it also on .Net section, search VFP section for ADO and return parameter. Same applies to .Net I think. In .Net it should be easier since a return parameter to return a value recordset needs to be closed.
>>BTW: You specify commandtext and commandtype to be a stored procedure.
>>Cetin
>
>Cetin,
>Thank you for your reply. I don't have PUTM (I can justify it for myself, but I am having a hard time justifying it to my bosses {the VP and my wife <s>}), so I can't search. If you could link the message it would be great.
>
>What do you mean by: You specify commandtext and commandtype to be a stored procedure? I do specify that it is a SP in the commandtype, and I specify the command text in the contructor of the command.

Here it is (I can't believe I was so lucky to find it this much quickly):
Re: VFP/ADO/SQL stored procedure syntax Thread #1056781 Message #1057068

Depending on your needs you might use ExecuteNonQuery,ExecuteScalar,ExecuteReader.. A stored procedure might both return a dataset + a return value (and also fill output parameters if any).
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform