我想在 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
的此信息放在哪里。
最佳答案
您需要将SelectCommandType
更改为StoredProcedure:
<asp:SqlDataSource ID="SqlDataSourceViewRegistrants" runat="server"
ConnectionString="<%$ ConnectionStrings:Events2 %>"
SelectCommand="spGetAllRegistrants"
SelectCommandType="StoredProcedure"></asp:SqlDataSource>
关于asp.net - GridView 和存储过程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33780373/