Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calling a Stored Procedure with Output Parameter
Message
 
 
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:
01470706
Views:
40
>>
>>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform