Stored Procedure to handle mulitple insert parameters send by asp.net webform

Hi Experts,

I have an asp.net web form that passes a variable amount of parameters to insert into DB tables

It could be 2 parameters or one or 10 depending on the user

How do i declare the parameters in a stored procedure to accept these input parameters?

e.g

The web form asks users to enter contact names.. if more names are needed, dynamic textbox controls are created via button click

each contact name is added seperatly to an asp.net sqldatasource via insertparameters and it calls the sp to insert the values into the db

for the sp, i dont want to create 20 input parameters to cover all cases, say the user enters ten contact names(via ten seperate textboxes) on the webform

Create PROCEDURE test

@business_name varchar(50),
@business_code varchar(3),
@contact_name1 varchar(30),
@contact_name2 varchar(30),
@contact_name3 varchar(30),
@contact_name4 varchar(30),
@contact_name5 varchar(30),
@contact_name6 varchar(30),
..
@contact_name20 varchar(30)

should the multiple values be sent differently to the stored procedure?
miguel_jAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Refael AckermannCommented:
0
Anurag ThakurTechnical ManagerCommented:
in sql stored procedures there is one beautiful thing and that is setting the default values to the parameters

@business_name varchar(50) = '',
@business_code varchar(3) = '',
@contact_name1 varchar(30) = '',
@contact_name2 varchar(30) = '',
@contact_name3 varchar(30) = '',
@contact_name4 varchar(30) = '',
@contact_name5 varchar(30) = '',
@contact_name6 varchar(30) = ''

now while calling the stored procedure you can supply only the patameters where you have the value and rest of the parameters will be initilized with the default values defined

the following link further defines default parameters in sql
http://www.sqlservercentral.com/articles/Stored+Procedures/usingparameterswithstoredprocedures/2004/
(you might have to register on the web site)
0
miguel_jAuthor Commented:
thank you for your help

So i do need to create many parameters to cover (not knowing how many times the user adds extra web controls..

i was wanting to create sp parameters based on how many parameters was sent from the web form? it will vary

say the user may enter 50 names? then taking those 50 names and adding them into a seperate rows using a loop?
0
Refael AckermannCommented:
One other option (if you know that the values will only be strings) is to "serialize" the values into a single string, for example by Joining them with ';' as delimiter. Then splitting the value in the sproc (http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648).


String[] values = new[] {"one", "two", "three"};
String serString = String.Join(";", values);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Anurag ThakurTechnical ManagerCommented:
i did not completely got your question previously

the best solution in this case should be passing and XML with object to the stored procedure and then reading the XML in the database and then looping it around and inserting or updating the multiple values to the database

sample
http://weblogs.asp.net/jgalloway/archive/2007/02/16/passing-lists-to-sql-server-2005-with-xml-parameters.aspx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.