Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 执行SqlCommand语句并在标签中显示结果_C#_Winforms_Sqlcommand - Fatal编程技术网

C# 执行SqlCommand语句并在标签中显示结果

C# 执行SqlCommand语句并在标签中显示结果,c#,winforms,sqlcommand,C#,Winforms,Sqlcommand,我正在执行这个存储过程,我想对它进行更改,而不是只返回所有结果然后处理它们。我想将存储过程第三列中的信息返回并显示在winforms应用程序的label.text中。我该怎么做呢 public IEnumerable GetGuids(int id) { using (SqlCommand _command = new SqlCommand("StoredProc")) { _command.Connection = new SqlConnection(conSt

我正在执行这个存储过程,我想对它进行更改,而不是只返回所有结果然后处理它们。我想将存储过程第三列中的信息返回并显示在winforms应用程序的label.text中。我该怎么做呢

public IEnumerable GetGuids(int id)
{
    using (SqlCommand _command = new SqlCommand("StoredProc"))
    {
        _command.Connection = new SqlConnection(conString);
        _command.Connection.Open();
        _command.CommandType = CommandType.StoredProcedure;
        _command.Parameters.AddWithValue("@ItemID", id);

        return _command.ExecuteReader(); 
    }
}
我想在存储过程的第3列中显示将返回的项,如下所示:itemrrow1/itemrrow2

public IEnumerable GetGuids(int id)
{    
  List<string> items = new List<string>();        
  using (SqlCommand _command = new SqlCommand("StoredProc"))
  {
      _command.Connection = new SqlConnection(conString);
      _command.Connection.Open();
      _command.CommandType = CommandType.StoredProcedure;
      _command.Parameters.AddWithValue("@ItemID", id);

      using (var reader = _command.ExecuteReader())
      {
         while (reader.Read())
         {
            items.Add(reader[2].ToString());
         }
      }        
  }
  return items;
}
或者以您想要的方式显示它


或者,无论您想如何显示它,它都将类似于reader.GetDecimal(columnIndex)

它将类似于reader.GetDecimal(columnIndex)

是否应该在
列表的末尾有()。
此外,我收到一个错误,说明无法将
项的
对象转换为
字符串
列表末尾是否应该有()。
另外,我收到一个错误,说明无法将
项的
对象
转换为
字符串。添加(读卡器[2])
label.Text = String.Join(",", items.ToArray());