【问题标题】:What's an easy way to update the value of a single column in a one row table with SQLite's sqlite-net-pcl library?使用 SQLite 的 sqlite-net-pcl 库更新单行表中单个列的值的简单方法是什么?
【发布时间】:2020-09-27 00:22:32
【问题描述】:

我正在使用 SQLite 的 sqlite-net-pcl 库,这是我拥有的表。我想知道的是,创建表后如何将值更新为2?

db2.CreateTable<Schema>();
db2.Insert(new Schema() { SchemaGuid = new Guid().ToString(), Version = 1 });
public class Schema
{
    [PrimaryKey, NotNull]
    public string SchemaGuid   { get; set; }
    public int    Version      { get; set; }
}
var version = RunQuery<int>($"SELECT Version FROM Schema").FirstOrDefault();

【问题讨论】:

    标签: c# sqlite xamarin


    【解决方案1】:

    您可以使用“UpdateAsync”以相同的PrimaryKey 更新版本值。

    插入记录:

    db2.InsertAsync(new Schema() { ID = 1, SchemaGuid = new Guid().ToString(), Version = 0 });
    

    更新:

    db2.UpdateAsync(new Schema() { ID = 1, SchemaGuid = new Guid().ToString(), Version = 2 });
    

    您可以使用以下代码检查列表中的所有记录:

    db2.Table<Schema>().ToListAsync();
    

    mroe详情可以参考MS文档https://docs.microsoft.com/en-us/xamarin/get-started/quickstarts/database?pivots=windows

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-24
      • 1970-01-01
      • 2010-09-15
      • 1970-01-01
      • 2021-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多