gpt4 book ai didi

c# - 使用 SQLitePCL-WP8.1 在 SqLite 中查找最大值

转载 作者:太空宇宙 更新时间:2023-11-03 21:27:52 25 4
gpt4 key购买 nike

我对将 SQlite 集成到通用应用程序还很陌生。我已经启动并运行了数据库。但现在我正试图找到一列的最大值。它没有返回预期值。 Db 填充了数据

var db = App.conn;
using (var statement = db.Prepare("SELECT MAX(Priority) as Priority FROM FOLDER; "))
{
statement.Step();
var result = (int)statement["Priority"];
}

异常表示转换错误,但 Priority 是 Integer 类型。

编辑

An exception of type 'System.InvalidCastException' occurred in JusWrite Trial.WindowsPhone.exe but was not handled in user code Additional information: Specified cast is not valid.

最佳答案

intInt32 而不是 Int64 的别名,因此 int != Int64。您只能将装箱结构转换为相同类型或其可空变体。在这种情况下,它恰好是 long/Int64 或 Nullable aka long?

要解决此问题,您需要先转换为 long,然后再转换为 int,或者只需使用 Convert.ToInt32

var result = (int)(long)statement["Priority"];

var result = Convert.ToInt32(statement["Priority"]);

进一步阅读 Representation and Identity

关于c# - 使用 SQLitePCL-WP8.1 在 SqLite 中查找最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25885573/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com