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();
有人可以帮忙吗?我收到的行/列没有数据。'这个错误抛出
答案 0 :(得分:0)
您没有调用Read Method
OleDbDataReader reader = command.ExecuteReader();
if(reader.Read())
{
string result = reader.GetValue(0).ToString();
MessageBox.Show(result);
}
connection.Close();
这只会从结果中读取第一行。如果你想要所有行,那么你需要写一些像这样的东西
OleDbDataReader reader = command.ExecuteReader();
List<string> data = new List<string>();
while(reader.Read())
{
data.Add(reader.GetValue(0).ToString());
}
connection.Close();