【问题标题】:Changing SQL Datasource stored procedure on button press按下按钮时更改 SQL 数据源存储过程
【发布时间】:2014-12-09 13:51:15
【问题描述】:

我想运行两个不同的存储过程。列出的第一个将在启动时运行并显示数据库中的所有条目。第二个我只想在按下按钮时运行,它只显示特定条目。像这样运行它们可能不是最好的主意,但我已经尝试了一些不同的东西,到目前为止还没有运气。有什么建议吗?

<asp:SqlDataSource ID="sqlDevRequestHistory" runat="server" ConnectionString="<%$ ConnectionStrings:TrackIt %>"
    SelectCommand="DevRequestHistory_SEL2" SelectCommandType="StoredProcedure" />
<asp:SqlDataSource ID="SqlDevReqestHistory" runat="server" ConnectionString="<%$ ConnectionStrings:TrackIt %>"
    SelectCommand="DevRequestHistory_SEL" SelectCommandType="StoredProcedure" />



public void btnShowAll_Click(object sender, EventArgs e)
    {

        using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["TrackIt"].ConnectionString))
        {
            using (var command = new SqlCommand("DevRequestHistory_SEL", connection)) 
            {
                command.CommandType = CommandType.StoredProcedure;
                connection.Open();

                command.ExecuteNonQuery();
            }
        }

    }

【问题讨论】:

    标签: c# asp.net stored-procedures sqldatasource


    【解决方案1】:

    我最终做的是在 asp.net 中设置的多视图中复制我的数据网格。使用它,我可以将不同的存储过程调用到不同的数据网格中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-22
      • 1970-01-01
      • 1970-01-01
      • 2013-04-02
      • 1970-01-01
      相关资源
      最近更新 更多