Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Calling a Stored Procedure with Output Parameter
Message
 
 
À
25/06/2010 21:55:19
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01470620
Message ID:
01470706
Vues:
41
>>
>>See sample code here http://www.mikesdotnetting.com/Article/54/Getting-the-identity-of-the-most-recently-added-record
>>
>>
>>//C#
>>string query = "AddCategory";
>>int ID;
>>string connect = @"Server=.\SQLExpress;Database=Northwind;Trusted_Connection=Yes;";
>>using (SqlConnection conn = new SqlConnection(connect))
>>{
>>  using (SqlCommand cmd = new SqlCommand(query, conn))
>>  {
>>    cmd.CommandType = CommandType.StoredProcedure;
>>    cmd.Parameters.AddWithValue("@Category", Category.Text);
>>    cmd.Parameters.Add("@CategoryID", SqlDbType.Int, 0, "CategoryID");
>>    cmd.Parameters["@CategoryID"].Direction = ParameterDirection.Output;
>>    conn.Open();
>>    cmd.ExecuteNonQuery();
>>    ID = (int)cmd.Parameters["@CategoryID"].Value;
>>  }
>>}
>
>I did it exactly as you show it and the @NextNumber parameter is still "0". I can drill right into the cmd object parameters and I can see the named parameter and it is zero. When I run the SP in SSMS I get zero for the value also but the other value is correct. How you get that other value is what is obviously missing.
>Tim

Tim,

I don't know what you're missing. I know that this code worked fine for me.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform