【问题标题】:how to pass stored procedure value into a webform? [closed]如何将存储过程值传递到 Web 表单中? [关闭]
【发布时间】:2013-10-17 10:48:19
【问题描述】:

我比较新鲜,我为我的 sql 表创建了一个存储过程,我想将这些数据显示到一个 aspx 页面中..

我需要..ajax,js,asp.net 的代码

【问题讨论】:

  • 已经用 Google 搜索过了?没找到文章?
  • 我试了几次都没有得到确切的代码
  • 我不会在这里提交此类问题,谢谢您的反馈..

标签: c# jquery asp.net sql


【解决方案1】:

从我的头顶是这样的:

using (SqlConnection con = new SqlConnection(ConnectionString)) {
    con.Open();
    using (SqlCommand command = new SqlCommand("ProcedureName", con)) {
        command.CommandType = CommandType.StoredProcedure;
        using(SqlReader reader = command.ExecuteReader()){
            if (reader.HasRows) {
                 while(reader.Read()) {
                     ... process SqlReader objects...
                 }
            }
        }
    }
}

编辑:抱歉,错过了“检索”信息。

【讨论】:

  • +1,除非您可以省略 reader.HasRows。如果它没有行,则 reader.Read() 将返回 false 并且 while 循环将退出。
  • 同意,我曾经使用 HasRows 代码的一部分来记录日志...有点坚持它,再也没有回去 :-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-01-31
  • 2012-09-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多