Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
| Search | Today's Posts | Mark Forums Read
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 23rd, 2007, 09:42 AM
Authorized User
 
Join Date: Mar 2007
Location: Beijing, Beijing, China.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to erictamlam Send a message via MSN to erictamlam Send a message via Yahoo to erictamlam
Default SQL Server StoredProcedure Parameter pass

Hi Experts:
I met a problem when trying to pass two parameters to SQL storedprocedure in C# programme.
Here is the definition of the storedprocedure:
CREATE PROC product_proc;1
(@d_salary int,@u_salary int)
AS
IF @d_salary IS NULL
BEGIN
PRINT 'offer minimum salary'
RETURN -1
END
IF @u_salary IS NULL
BEGIN
PRINT 'offer maximum salary'
RETURN -2
END
IF @u_salary < @d_salary
BEGIN
PRINT 'maximum salary<minimum salary!'
RETURN -3
END
IF NOT EXISTS (SELECT * FROM Product WHERE price BETWEEN @d_salary AND @u_salary)
BEGIN
PRINT 'No records!'
RETURN -100
END
SELECT * FROM Product WHERE price>@d_salary AND price<@u_salary
RETURN 0

How to pass the two parameters "d_salary " and "u_salary" in C# programme?
part of the C# programme:

//Specific SQL Server-specific connection string
            SqlConnection thisConnection = new SqlConnection("Server=ERIC;Integrated Security=True;DataBase=pubs");

            //Open connection
            thisConnection.Open();

            //Create command for this connection
            SqlCommand thisCommand = thisConnection.CreateCommand();
            thisCommand.CommandType = CommandType.StoredProcedure;
            thisCommand.CommandText = "product_proc";

Thanks for your kind help
Eric

ERIC
__________________
ERIC
 
Old March 23rd, 2007, 10:28 AM
Friend of Wrox
 
Join Date: Dec 2006
Location: , , .
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi
for each variable in your store procedure you might write flowing code

thisConnection.Parameters.ADD("@variable Name",SqlDbType,variable size ).Value=<value for variable>

kiani,mehdi
 
Old March 23rd, 2007, 10:37 PM
Authorized User
 
Join Date: Mar 2007
Location: Beijing, Beijing, China.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to erictamlam Send a message via MSN to erictamlam Send a message via Yahoo to erictamlam
Default

great appreciation,angelboy!I've got it done!

ERIC
 
Old March 27th, 2007, 01:31 AM
Friend of Wrox
 
Join Date: Dec 2006
Location: , , .
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you ae wellcome
anouther way eseaier than previuse way that i saied is :

sqlCommandName.Parameters.AddWithValue('@variableN ame',<variable value>)

enjoy it
regards
kiani,mahdi




Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass parameter value to CR SQL Command vijaykumartaduri BOOK: Professional Crystal Reports for VS.NET 3 July 31st, 2007 12:13 AM
Problem with pass parameter in hyperLinke server alamoudi ASP.NET 2.0 Professional 1 May 6th, 2007 05:03 PM
How to pass Table Name as a parameter in SQL query visualbrin Reporting Services 1 October 13th, 2006 04:08 PM
Help with using a StoredProcedure to write to SQL garryg ASP.NET 1.0 and 1.1 Basics 1 February 17th, 2006 03:42 PM
Pass Crystal parameter to a SQL sp cphspain Crystal Reports 5 January 27th, 2005 07:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.