[英]'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();
Could anyone help? 有人可以帮忙吗? I'm getting 'No data exists for the row/column.' 我收到“行/列没有数据”。 this error thrown 抛出此错误
You are not calling Read Method 您没有在调用Read Method
OleDbDataReader reader = command.ExecuteReader();
if(reader.Read())
{
string result = reader.GetValue(0).ToString();
MessageBox.Show(result);
}
connection.Close();
This will just read the first row from the result.If you want all the rows then you will need to write some thing like this 这只会从结果中读取第一行。如果想要所有行,则需要编写如下内容
OleDbDataReader reader = command.ExecuteReader();
List<string> data = new List<string>();
while(reader.Read())
{
data.Add(reader.GetValue(0).ToString());
}
connection.Close();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.