470,849 Members | 1,215 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

stored procedure in sqlexpress

I have created this example in sqlexpress
ALTER PROCEDURE [dbo].[gettaxbracket]

@annualtax FLOAT


SELECT begin1,end1,deductedamount,pecentageextra
FROM tax
WHERE @annualtax BETWEEN begin1 AND end1
can u please tell me how to gain access to the @annualtax parameter in
C#. An then i want to assign a textbox value to it.thanks

Mar 29 '07 #1
2 3894
I think you are asking about talking in the value of the annualtax via a
input box and pass that parameter to the SQL SP via your code and get teh
result back to your code right?

The answer to your question depend on what technique you used to communicate
with your database. Whether you use a datareader or dataset etc.. but in
generatl assuming that you are using SQL Helper / Data Reader approach. It
does provide a method to Execute a SqlCommand against the database providing
as a parameters.

If you google a bit you may easily find a sample code.. I cannot give any
right now since yoru question is too broad


<je*@auto-soft.co.zawrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
>I have created this example in sqlexpress
ALTER PROCEDURE [dbo].[gettaxbracket]

@annualtax FLOAT


SELECT begin1,end1,deductedamount,pecentageextra
FROM tax
WHERE @annualtax BETWEEN begin1 AND end1
can u please tell me how to gain access to the @annualtax parameter in
C#. An then i want to assign a textbox value to it.thanks

Mar 29 '07 #2
I copied this from http://www.codeproject.com/useritems/simplecodeasp.asp

Stored Procedures are a set of sql commands which are compiled and are
stored inside the database. Every time you execute a sql command, the
command is parsed, optimization is done and then the command is
executed. Parsing and optimization the command each time you run the
query is very expensive. To solve this we have a set of commands
collectively called as stored procedure, which are already parsed and
optimized and are executed when ever we call them. This article
describes about how to call the stored procedures through Ado.net and
how to handle the output parameters of the called stored procedures.

Initially create a object of SqlConnection class which is available in
System.Data.SqlClient namespace. You has to provide the connection
string as a parameter which includes the Data Source name, the
database name and the authentication credentials. Open the connection
using the Open() method.

SqlConnection con = new SqlConnection("Data Source= ;
initial catalog= Northwind ; User Id= ; Password=

Create the following stored procedure on the Region table in the
Northwind database which accepts two parameters and does not have any
output parameters.

@RegionDescription NCHAR(50)) AS
SET RegionDescription = @RegionDescription
Create a SqlCommand object with the parameters as the name of the
stored procedure that is to be executed and the connection object con
to which the command is to be sent for execution.

SqlCommand command = new SqlCommand("RegionUpdate",con);
Change the command objects CommandType property to stored

command.CommandType = CommandType.StoredProcedure;
Add the parameters to the command object using the Parameters
collection and the SqlParameter class.

SqlParameter("@RegionID",SqlDbType.Int,0,"RegionID "));


Specify the values of the parameters using the Value property of the



Excecute the stored procedure using the ExecuteNonQuery method which
returns the number of rows effected by the stored procedure.

int i=command.ExecuteNonQuery();
Now let us see how to execute stored procedures which has output
parameters and how to access the results using the output parameters.

Create the following stored procedure which has one output parameter.

ALTER PROCEDURE RegionFind(@RegionDescription NCHAR(50)

SELECT @RegionDescription =RegionDescription from Region
where RegionID=@RegionID

The above stored procedure accepts regionID as input parameter and
finds the RegionDescription for the RegionID input and results it as
the output parameter.

SqlCommand command1 = new SqlCommand("RegionFind",con);
command1.CommandType = CommandType.StoredProcedure;
Add the paremeters to the command1

command1.Parameters.Add(new SqlParameter
("@RegionDescription",SqlDbType.NChar ,
0,50,"RegionDescription",DataRowVersion.Default,nu ll));
command1.Parameters.Add(new SqlParameter("@RegionID" ,
0 ,
"RegionID" ));
Observe that the parameter RegionDescription is added with the
ParameterDirection as Ouput.

specify the value for the input parameter RegionID.

command1.Parameters["@RegionID"].Value = 4;
Assign the UpdatedRowSource property of the SqlCommand object to
UpdateRowSource.OutputParameters to indicate that data will be
returned from this stored procedure via output parameters.

command1.UpdatedRowSource =
Call the stored procedure and access the RegionDescription for the
RegionID 4 using the value property of the parameter.

string newRegionDescription =(string)

Close the sql connection.

In the same way you can call the stored procedure that returns a set
of rows by defining the parameters as appropriate and executing the
command using ExecuteReader() that is used to traverse the records
returned by the command.




Mar 29 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by J. S. EDV | last post: by
2 posts views Thread by jed | last post: by
3 posts views Thread by leesquare | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.