这应该以最快的方式为您提供所需的字符串列表。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;