【发布时间】:2021-08-27 13:29:23
【问题描述】:
所以我试图从现有的 SQLite 数据库中读取值,它似乎最初可以工作,但是在查询之后,当我尝试读取它们时,它似乎丢失了值。
我在这里做错了什么?
https://www.youtube.com/watch?v=Yvj6BTjts3M
public ObservableCollection<Asset> GetAllAssets()
{
_DbConn.Open();
var command = _DbConn.CreateCommand();
var allAssets = new ObservableCollection<Asset>();
command.CommandText =
@"
SELECT *
FROM asset
";
using (var reader = command.ExecuteReader())
{
while (reader.HasRows)
{
Asset asset = new Asset();
asset.AssetId = reader.GetInt32(0);
asset.AssetTypeId = reader.GetInt32(1);
asset.Name = reader.GetString(2);
asset.FileLocation = reader.GetString(3);
asset.IsCustom = reader.GetBoolean(4);
asset.AssetSectionId = reader.GetInt32(5);
asset.ThumbFileLocation = reader.GetString(6);
allAssets.Add(asset);
}
}
_DbConn.Close();
return allAssets;
}
【问题讨论】:
-
您应该在视频下方写下评论,说明教的东西不起作用。并发布此问题的链接;)