C# 执行SqlCommand语句并在标签中显示结果
我正在执行这个存储过程,我想对它进行更改,而不是只返回所有结果然后处理它们。我想将存储过程第三列中的信息返回并显示在winforms应用程序的label.text中。我该怎么做呢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
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());