【问题标题】:Xamarin - get max timestamp from table using SQLite-net PCLXamarin - 使用 SQLite-net PCL 从表中获取最大时间戳
【发布时间】:2016-11-30 10:10:06
【问题描述】:

我正在尝试获取表中的最大时间戳。我正在使用SQLite-net PCL,但 value 总是返回 null。

我检查了数据库实例是否正确传递并且数据库中是否填充了数据。

这是我的方法:

public long? GetLastItemsTimeStamp()
{
    try
    {
        List<long?> TimeStamp = db.Query<long?>("SELECT max (TimeStamp) FROM Items ;" ) ;
        return  (TimeStamp.Count > 0) ? TimeStamp[0] : null ;
    }
    catch(Exception e)
    {

    }

    return null;
}

【问题讨论】:

  • 我没有得到任何异常
  • 来自 quickWatcher ,它返回空值并且没有进入 catch 块,这是执行查询的正确方法吗?
  • 不,我的数据库只有两项填充了数据,当我查看观察者时,它给了我奇怪的消息“方法Query&lt;long?&gt;' not found in type SQLite.SQLiteConnection'。”
  • 返回空值请来聊天

标签: sqlite xamarin


【解决方案1】:

我想办法做到这一点,希望这对面临同样问题的人有所帮助。

 public long? GetLastItemsTimeStamp()
 {
     var table = db.Table<Item>();
     long timestamp = table.Max(x => x.TimeStamp);
     return timestamp ;
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 2017-07-02
    • 2018-03-22
    相关资源
    最近更新 更多