View Full Version : Passing a value to a stored procedure

03-19-2006, 07:24 PM
I am currently trying to pass a value from a url to a sqldatasource control. There seems to be a lack of information on how to do this. I would greatly appreciate the help.

I am passing a variable "dept" through the url (i.e. products.aspx?dept=23) and trying to insert it into the Where part of my SQL statement.

The stored procedure is defined as follows:

CREATE PROCEDURE ProductSearch (@Search int)
EXEC('SELECT parts.name, manufacturer.name AS Expr1, parts.model, parts.price, parts.image1 FROM manufacturer INNER JOIN parts ON manufacturer.ID = parts.brand WHERE parts.category = @Search')


The datasource control:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString1 %>"
SelectCommandType="StoredProcedure" SelectCommand="ProductSearch">

I am very new to asp and have little understanding of these controls. I am completely clueless as to how to pass the value of my variable "Search" to the stored procedure. I appreciate any help you can give.