Assigning value to parameter in stored procedure

  • Thread starter Thread starter jed
  • Start date Start date
J

jed

I have tried

sqlCommand1.Parameters[0].Value = float.Parse(textBox1.Text);
but the debugger says that it cant see the parameter

How can i gain access to the parameter in C# EXpress.thanks in
advance(i am newbie).
 
I have tried

sqlCommand1.Parameters[0].Value = float.Parse(textBox1.Text);
but the debugger says that it cant see the parameter

How can i gain access to the parameter in C# EXpress.thanks in
advance(i am newbie).

Stored Procedure is
BEGIN

SELECT begin1,end1,deductedamount,pecentageextra
FROM tax
WHERE @annualtax BETWEEN begin1 AND end1
END

I can do not using stored procedure but want to learn how to with a
stored procedure
 
What do you mean it can't see the parameter? What are you putting in
the debugging window?
 
Hi,

Did you create the parameter first?

When you are talking about the debugger, are you refering to the "watch"
panel?
are you seeing it AFTER that line?
 
You have to add the parameters to the command object.

SqlCommand cmd = new SqlCommand();
cmd.Connection = myConnection;
cmd.CommandText = "mySpName";

cmd.Parameters.AddWithValue("@myParameterName",
float.Parse(textBox1.Text);

or this:

SqlParameter p = new SqlParameter();
p.ParameterName = "@myParameterName";
p.Value = float.Parse(textBox1.Text);
cmd.Parameters.Add(p);

Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top