Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calling a Stored Procedure with Output Parameter
Message
From
26/06/2010 08:49:42
 
 
To
25/06/2010 21:55:19
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01470620
Message ID:
01470686
Views:
25
>>
>>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

Hi Tim,

if I'm following this conversation correctly, then there seems to be some difficulty in getting back the output parameter from a stored procedure. Is that right? What alternatives do I have that I can try?
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform