miguel_j
asked on
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?
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?
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)
@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)
ASKER
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://blog.benhall.me.uk/2007/07/sql-server-2008-table-value-parameters.html