'No data exists for the row/column.' Oledb 异常

'No data exists for the row/column.' Oledb Exception

connection.Open();
OleDbCommand command = new OleDbCommand("SELECT [Names] FROM Test", 
connection);

OleDbDataReader reader = command.ExecuteReader();
string result = reader.GetValue(0).ToString();
        MessageBox.Show(result);
        connection.Close();

有人能帮忙吗?我收到 'No data exists for the row/column.' 抛出的错误

您没有调用读取方法

    OleDbDataReader reader = command.ExecuteReader();
    if(reader.Read())
    {
       string result = reader.GetValue(0).ToString();
       MessageBox.Show(result);
     }
    connection.Close();

这将只读取 result.If 的第一行,你需要所有行然后你需要写一些这样的东西

    OleDbDataReader reader = command.ExecuteReader();        
    List<string> data = new List<string>();
    while(reader.Read())
    {
      data.Add(reader.GetValue(0).ToString());
    }        
    connection.Close();