473,729 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

stored procedure in sqlexpress

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

@annualtax FLOAT

AS
BEGIN

SELECT begin1,end1,ded uctedamount,pec entageextra
FROM tax
WHERE @annualtax BETWEEN begin1 AND end1
END
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 4104
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

Nirosh.

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

@annualtax FLOAT

AS
BEGIN

SELECT begin1,end1,ded uctedamount,pec entageextra
FROM tax
WHERE @annualtax BETWEEN begin1 AND end1
END
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.Sql Client 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=
'");

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

CREATE PROCEDURE RegionUpdate (@RegionID INTEGER,
@RegionDescript ion NCHAR(50)) AS
SET NOCOUNT OFF
UPDATE Region
SET RegionDescripti on = @RegionDescript ion
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("Reg ionUpdate",con) ;
Change the command objects CommandType property to stored
procedure.

command.Command Type = CommandType.Sto redProcedure;
Add the parameters to the command object using the Parameters
collection and the SqlParameter class.

command.Paramet ers.Add(new
SqlParameter("@ RegionID",SqlDb Type.Int,0,"Reg ionID"));

command.Paramet ers.Add(new
SqlParameter("@ RegionDescripti on",SqlDbType.N Char,
50,"RegionDescr iption"));

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

command.Paramet ers[0].Value=4;

command.Paramet ers[1].Value="SouthEa st";

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

int i=command.Execu teNonQuery();
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(@Reg ionDescription NCHAR(50)
OUTPUT,
@RegionID INTEGER )AS

SELECT @RegionDescript ion =RegionDescript ion from Region
where RegionID=@Regio nID

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

SqlCommand command1 = new SqlCommand("Reg ionFind",con);
command1.Comman dType = CommandType.Sto redProcedure;
Add the paremeters to the command1

command1.Parame ters.Add(new SqlParameter
("@RegionDescri ption",SqlDbTyp e.NChar ,
50,ParameterDir ection.Output,f alse,
0,50,"RegionDes cription",DataR owVersion.Defau lt,null));
command1.Parame ters.Add(new SqlParameter("@ RegionID" ,
SqlDbType.Int,
0 ,
"RegionID" ));
Observe that the parameter RegionDescripti on is added with the
ParameterDirect ion as Ouput.

specify the value for the input parameter RegionID.

command1.Parame ters["@RegionID"].Value = 4;
Assign the UpdatedRowSourc e property of the SqlCommand object to
UpdateRowSource .OutputParamete rs to indicate that data will be
returned from this stored procedure via output parameters.

command1.Update dRowSource =
UpdateRowSource .OutputParamete rs;
Call the stored procedure and access the RegionDescripti on for the
RegionID 4 using the value property of the parameter.

command1.Execut eNonQuery();
string newRegionDescri ption =(string)
command1.Parame ters["@RegionDescrip tion"].Value;

Close the sql connection.

con.Close();
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.

Regards

http://www.auratius.co.za

Auratius

Mar 29 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2584
by: den 2005 | last post by:
Hi everybody, I created several stored procedure in a local sql server 2005 express database, now when I call/execute them in the asp.net 2.0 web page, it returns an error message of "Cannot find the stored procedure '<proc_name>'", this is funny, when I execute the command in a sql query window "exec sp_GetAllArticles", it also returns cannot find stored procedure, but when I execute the "Use <DBName>" and then execute the statement, it...
10
2940
by: J. S. EDV | last post by:
Hello, I have got a little problem with stored procedures and C#. I have got a stored procedure which should only insert something in a table. For example: ALTER PROCEDURE DBO.PROC1 AS insert into dbo.Test values ('test')
0
2634
by: Jon Paal | last post by:
error : "Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'." using VWD 2005 with sqlexpress 2005 I am trying to create membership roles and users......
2
1470
by: jed | last post by:
I have created a stored procedure in SQLExpress management.I need to retrieve a numeric value that the stored procedure creates and use it in a C# application.Please help thanks. USE GO /****** Object: StoredProcedure . Script Date: 03/19/2007 00:54:23 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON
2
992
by: poops2468 | last post by:
I have a very simple Insert Stored Procedure. When I run it from the Server Explorer, it inserts the records just fine. However, when I try to call it from my form, it does not update the table. The weird thing is that it does return one row effected and if I try it again, I am told my primary key is not unique (meaning the first record is in there somewhere). When I exit my app, my table is just the same as it was before the inserts. Do I need...
4
18817
by: smartin | last post by:
Hi, I'm having problem retrieving data from an SQL stored procedure. I tried debugging but it wont give a the reason for the error. it just throws an exception after executing cmd.ExecuteNonQuery without any details. Can anyone please help me.. Im stuck on it since 2 days Thanks Stored Procedure
3
5117
by: leesquare | last post by:
Hello, I need some help getting output values from my stored procedures when using adodbapi. There's an example testVariableReturningStoredProcedure in adodbapitest.py, and that works for my system. But my stored procedure also inserts and accesses a table in the database. Here's what I have it boiled down to: So, when I have
3
5048
by: cmrhema | last post by:
Hi, Kindly excuse if I am posting in the wrong place. I am using Visual Studio 2008, .net framework 3.5, asp.net , c# and sql server 2005. I am supposed to pass stored procedures from client to wcf service. The WCF service should execute the stored procedure and return the result.
2
14658
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how can I pass null value as parameter to the database stored procedure programattically using C#? Although I can check for empty column (the following code passes string.Empty as parameter but how to pass null value?), I cannot check for null value...
0
8917
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9281
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2163
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.