读书人

存储过程传参数解决办法

发布时间: 2013-11-04 16:56:03 作者: rapoo

存储过程传参数
<asp:SqlDataSource ID="SqlDataSource2" ConnectionString="<%$ ConnectionStrings:WorkConnectionString %>"
ProviderName="System.Data.SqlClient" SelectCommandType="StoredProcedure" SelectCommand="usp_GetProductOfPD"
runat="server">


存储过程是带参数的,直接在界面绑定的
我如何在界面上直接传递参数勒
[解决办法]
你例子

CREATE PROCEDURE [dbo].[GetProductsByCategoryID]
@ProductSubcategoryID int
AS
SELECT ProductID, Name, ProductNumber FROM Production.Product
WHERE ProductSubcategoryID=@ProductSubcategoryID ORDER BY ProductID


Categories:
<asp:DropDownList ID="lstCategories" DataSourceID="categoriesSource" runat="server"
DataValueField="ProductSubcategoryID" DataTextField="Name" AutoPostBack="true"></asp:DropDownList>

<asp:SqlDataSource ID="productsSource" runat="server" ProviderName="System.Data.SqlClient"
ConnectionString="<%$ ConnectionStrings:AdventureWorks %>"
SelectCommand="GetProductsByCategoryID" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="lstCategories" Name="ProductSubcategoryID" PropertyName="SelectedValue"/>
</SelectParameters>
</asp:SqlDataSource>

读书人网 >asp.net

热点推荐