SQLiteDataReader.Read()
不会回复false,即使它包含数据。
1.我一直在一些数据控制器上运行测试,但每次我从db中检索数据时,它都因为某种原因无法工作,确切地说,Read()没有进入循环来读取其中的数据。
1.连接成功,数据已读取,我在调试器中观察到了,请看下面的截图。
下面的代码是我正在做的,预计将进入try块中的while循环。
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
{
SQLiteCommand command = new SQLiteCommand(connection);
SQLiteDataReader reader = null;
//Make sure to ignore class names below, the problem isn't related to them they are changed for sake of demonstration
Dictionary<string, SomeDTO> output = new Dictionary<string, SomeDTO>();
try
{
command.CommandText = $"SELECT * FROM {TableName}";
connection.Open();
reader = command.ExecuteReader();
while (reader.Read())
{ //This loop is never entered
output.Add(reader.GetString(0), ConvertReaderToObject(reader));
}
}
catch (Exception ex)
{
Log.Error("SOME-LOG IRRELEVANT"+ex.Message);
}
finally
{
if(reader != null)
{
reader.Close();
}
command.Dispose();
connection.Close();
}
return output;
}
}
在下面的图片中,您可以看到读取器对象上的调试器详细信息,数据已按预期读取...
1条答案
按热度按时间ckx4rj1h1#
@TimSchmelter回答,发帖解决这个问题不会引起人们的注意。调试器本身使用
reader
中的数据,因此我可以看到调试器中的数据。直接从catch开始调试,将显示while循环中有一个异常。