Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
数据Sqlite Insert返回Null_Sqlite_Return Value_Simple.data - Fatal编程技术网

数据Sqlite Insert返回Null

数据Sqlite Insert返回Null,sqlite,return-value,simple.data,Sqlite,Return Value,Simple.data,我使用Simple.Data将数据插入Sqlite数据库。我在wiki上读到Insert返回插入的数据。我需要获取最新的rowID(标识)。但是我得到了空值 使用NuGet的稳定版本 var db = Database.OpenFile("Database.db"); var x = db.Scan.Insert(Name:"Test", Description:"test", CreationDate:DateTime.Now, DocumentDate:DateTime.Now, Modif

我使用Simple.Data将数据插入Sqlite数据库。我在wiki上读到Insert返回插入的数据。我需要获取最新的rowID(标识)。但是我得到了空值

使用NuGet的稳定版本

var db = Database.OpenFile("Database.db");
var x = db.Scan.Insert(Name:"Test", Description:"test", CreationDate:DateTime.Now, DocumentDate:DateTime.Now, ModifiedDate:DateTime.Now);
数据库模式:

CREATE TABLE Scan ( 
    ID           INTEGER         PRIMARY KEY,
    Name         NVARCHAR( 50 )  NOT NULL,
    Description  TEXT,
    CreationDate DATETIME        NOT NULL,
    DocumentDate DATETIME        NOT NULL,
    ModifiedDate DATETIME        NOT NULL 
);
这对SQLite有效吗?如果没有,检索插入记录的rowID的最佳方法是什么?

也有同样的“问题”。 问题在于您的模式

您必须向主键列添加标识:

ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
然后返回该行,即使用该行创建新对象:

var x = db.Scan.Insert(Name:"Test", Description:"test", CreationDate:DateTime.Now, DocumentDate:DateTime.Now, ModifiedDate:DateTime.Now);
return new Scan { ID = (int)x.ID, Name = x.Name, ... }
从Wiki:

如果在表上定义了标识列,则插入 方法都将返回从 数据库,因此设置了所有默认值。在0.4中,支持其他 将添加获取插入行的方法