您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

从SELECT查询返回多个值

从SELECT查询返回多个值

这应该以最快的方式为您提供所需的字符串列表。reader.GetString(0)表示您从索引为0的列(即第一个索引)中获取一个字符串值。

List<string> result = new List<string>();

using (sqlConnection connection = new sqlConnection(databaseConnectionString))
{
  connection.open();
  using (sqlCommand command = new sqlCommand(query, connection))
  {
    command.CommandType = CommandType.Text;
    using (sqlDataReader reader = command.ExecuteReader())
    {
      while (reader.Read())
      {
        result.Add(reader.GetString(0));
      }

      reader.Close();
    }
    command.Cancel();
  }
}

return result;
其他 2022/1/1 18:53:07 有306人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶