Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
Password Reminder
Register
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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



Reply With Quote
  #2 (permalink)  
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
Reply With Quote
  #3 (permalink)  
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


Reply With Quote
  #4 (permalink)  
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 ...

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:48 PM.


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