Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calling a Stored Procedure with Output Parameter
Message
From
25/06/2010 19:49:00
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:
01470665
Views:
29
>>>>>You're right, I miscounted. Did you also pass 10 0s ?
>>>>
>>>>Yes, as a string
>>>
>>>Did you test SP by itself just in case - though it's so simple I don't see a reason why it would not work.
>>
>>Just did and it seems to work. @NextNumber is "0000001045" just like I set it in the SP and the return value is 0 as expected. I will step into the C# code to see why it doesn't get back to there.
>>Tim
>
>What is your C# code? Did you remove extra parameter's declaration?

Yes, I tried it about a dozen ways. I tried this too.
SqlConnection conn = new SqlConnection(this.GetConnectionString("PantryWare"));
			

SqlCommand cmd = new SqlCommand();
object newVal;
cmd.CommandText = "dbo.GetNextNumber";
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param = new SqlParameter("@NextNumber", "0000000000");
param.Direction = ParameterDirection.Output;
cmd.Parameters.Add(param);
cmd.Connection = conn;
conn.Open();

newVal = cmd.ExecuteScalar();
conn.Close();

string myNumber = newVal.ToString();
newVal comes back Null.
Tim
Timothy Bryan
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform