GridView和存储过程?

时间:2015-11-18 12:40:54

标签: asp.net stored-procedures gridview

我想在Visual Studio中使用GridView。我完成了他们的教程,并设置了它。但是,我不知道如何使用我的存储过程。

它让我了解了这个:

 <asp:SqlDataSource ID="SqlDataSourceViewRegistrants" runat="server" 
        ConnectionString="<%$ ConnectionStrings:Events2 %>" 
        SelectCommand="SELECT * FROM [Registrant]"></asp:SqlDataSource>

我想以某种方式用存储过程替换SelectCommand

sqlCmd.CommandType = System.Data.CommandType.StoredProcedure;
sqlCmd.CommandText = "spGetAllRegistrants";

我不确定将此信息放在spGetAllRegistrants

的哪个位置

1 个答案:

答案 0 :(得分:4)

您需要将SelectCommandType更改为 StoredProcedure

<asp:SqlDataSource ID="SqlDataSourceViewRegistrants" runat="server" 
ConnectionString="<%$ ConnectionStrings:Events2 %>" 
SelectCommand="spGetAllRegistrants"
SelectCommandType="StoredProcedure"></asp:SqlDataSource>
相关问题