【问题标题】:Get the value of a stored procedure and pass that as a parameter to another stored procedure获取存储过程的值并将其作为参数传递给另一个存储过程
【发布时间】:2012-11-19 19:59:58
【问题描述】:

我需要获取这个存储过程的值并将其作为参数传递给另一个存储过程。

SqlCommand GetName = new SqlCommand("usp_GetName", sqlcon);
GetName.CommandType = CommandType.StoredProcedure;
GetName.Parameters.AddWithValue("@printer", printerguid);

这个存储过程有一个简单的选择语句,在任何给定点只返回一行。我需要获取该数据并将 tat 作为参数传递到其他地方...请告诉我如何从该存储过程中获取值并将其存储在变量中

【问题讨论】:

  • 过程返回多少个值,需要存储多少个值?

标签: c# asp.net ado.net


【解决方案1】:

如果它只返回一个值,请使用它并将其转换为它的类型(stringint 等)

var returnedValue = GetName.ExecuteScalar();

如果您有超过 1 个字段,您应该使用:

using(IDataReader reader = GetName.ExecuteReader())
{
  if (reader.Read())
  {
    // Populate any object using reader.GetString(reader.GetOrdinal("FieldName"))
    // Replace GetString for any data type you need.
  }
  else
  {
    // No rows returnes
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-13
    • 1970-01-01
    • 2013-08-29
    • 2019-10-13
    • 2015-08-24
    • 2010-10-19
    • 1970-01-01
    • 2016-11-05
    相关资源
    最近更新 更多