Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
| Search | Today's Posts | Mark Forums Read
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 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 February 22nd, 2007, 06:15 PM
Friend of Wrox
 
Join Date: Apr 2006
Location: , , .
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to pass value to stored procedure?

Hi,

i need to insert a record 1 or more times, depending of a variable in code-behind:
dim amount as integer
amount= value (e.g. 3)

My problem is: how to pass that variable to the stored procedure?
I tried with this but nothing happens:

comd.Parameters.Add("@amount", SqlDbType.NVarChar, 10).Value = amount_of_details

Maybe is my stored procedure wrong?
Thanks
H.

Here is it:
----------

ALTER PROCEDURE dbo.insert_table
 (
@field1 nvarchar(10)
,...
)
AS
Declare @iLoopNumber int
Declare @amount int
BEGIN TRAN

SET @iLoopNumber = 1

SET @amountr


While (@iLoopNumber <= @amount)

BEGIN

INSERT INTO table(field1,...)

VALUES (....))

 SET @iLoopNumber = @iLoopNumber +1

End


COMMIT TRAN



 
Old February 23rd, 2007, 03:21 AM
Authorized User
 
Join Date: Sep 2004
Location: Edegem, Antwerpen, Belgium.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Did you set the CommandType property of your SqlCommand to StoredProcedure?

Greetz,

Geert

http://geertverhoeven.blogspot.com
 
Old February 23rd, 2007, 06:04 AM
Friend of Wrox
 
Join Date: Apr 2006
Location: , , .
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, thanks for replying..
yes, i did.

Actually, my question is: can i assign the value of variable 'amount' to a Declare @var with the command "comd.Parameters.Add("@amount", SqlDbType.NVarChar, 10).Value = amount" or this is only for assigning a parameter within the 'Values' of the 'Insert' statement in the stored procedure?

If not, how to import 'amount' into the SP?

I guess i have also to make a loop in the code-behind for the parameters like this:

amount = 3 'example
comd.Parameters.Add("@amount", SqlDbType.Int).Value = amount
For i = 1 to amount
comd.Parameters.Add("@field1", SqlDbType.Int).Value = var1
Next


 
Old February 23rd, 2007, 11:43 AM
Friend of Wrox
 
Join Date: Apr 2006
Location: , , .
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I found it.I must put @amount with the other paramaters, not with Declare ...





Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass XML parameter to stored procedure BCullenward Classic ASP Databases 3 September 10th, 2008 02:07 PM
how to pass array to oracle stored procedure? zhao2007 Hibernate 1 March 21st, 2008 03:51 PM
pass null to the parameter in the stored procedure kokila BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 July 12th, 2007 03:02 AM
How to pass a parameter to a stored procedure? MaxGay2 VB.NET 2002/2003 Basics 1 November 8th, 2006 02:48 PM
How will I pass stored procedure in an asp shoakat SQL Server 2000 1 July 15th, 2004 10:28 PM





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