manraj82
manraj82

Reputation: 6325

asp.net stored procedure,multiple values in a single parameter

Im fairly new to Asp.Net arena here guys,so please bear with me if say something that's not logical.

I have a procedure that binds to a grid-view that displays data based on the selection made from a drop-down box. It works fine when a single value is sent but I'm thinking of doing multiple selection from the drop-down[using checkboxes] or even using a list-view, and I'm confused how to go about it. This is the code for the stored procedure. At the moment it accepts only a single value. For e.g., if I select Africa from the drop-down it displays all the cities from Africa. But now I would like to have multiple selections for the drop-down so that the grid display cities from more than one country.

CREATE PROCEDURE sp_getCities 
(
@p_country  nvarchar(50)
)
AS

SELECT country, cities
FROM world WHERE country=@p_country

I'm sure there are people who must have come across situations like this. If you have could you please provide me with a link to a tutorial or a solution?

Upvotes: 0

Views: 1172

Answers (2)

LukeH
LukeH

Reputation: 269658

Here's the (almost canonical) answer:

Upvotes: 2

William Xifaras
William Xifaras

Reputation: 5312

One way is to pass XML into a stored procedure and using the system stored procedure sp_xml_preparedocument. Essentially, you pass XML into the stored procedure and operate on it in a SET oriented manner.

Check out this link to get you started with this approach.

http://msdn.microsoft.com/en-us/library/ms187367.aspx

Upvotes: 0

Related Questions