我在尝试插入我的sqlite db时不断收到此错误。其他插入工作正常,但它似乎没有超出这一点。有没有人遇到过这个错误?你怎么解决?
以下是显示错误的代码和应用程序输出。
public long SaveSamplePoints(string endDate,string startDate,string Who,string altitude,string height)
{
double lat = 1.2607;
double lon = 36.804;
var dbconn = new SQLiteConnection(dbHandler.WritableDatabase.Path) ;
using(dbconn){
return dbconn.Insert (new SamplePointTable {
LATITUDE = lat,
LONGITUDE = lon,
});
}
输出如下:
[DataActivity] SQLite.SQLiteException: Constraint
[DataActivity] at SQLite.PreparedSqlLiteInsertCommand.ExecuteNonQuery (System.Object[] source) [0x00000] in <filename unknown>:0
[DataActivity] at SQLite.SQLiteConnection.Insert (System.Object obj, System.String extra, System.Type objType) [0x00000] in <filename unknown>:0
修改 这就是SamplePointTable的样子:
[Table("Sample_Point")]
public class SamplePointTable
{
// table sample points tags
public static string TABLE_SAMPLE_POINT= "Sample_Point";
[PrimaryKey, AutoIncrement,Column("_id")]
public int SAMPLE_POINT_ID { get; set;}
[Column("height")]
public int HEIGHT{ get; set;}
[Column("latitude")]
public double LATITUDE { get; set;}
[Column("longitude")]
public double LONGITUDE { get; set;}
[Column("start_date")]
public DateTime START_DATE { get; set;}
[Column("end_date")]
public DateTime END_DATE{ get; set;}
[Column("who")]
public static string WHO { get; set;}
[Column("user_id")] //foreign key column
public int USER_ID { get; set;}
public static void OnCreate(SQLiteDatabase database){
database.ExecSQL(CREATE_TABLE_SAMPLE_POINT);
}
public static void OnUpgrade(SQLiteDatabase database, int oldVersion,
int newVersion) {
Log.Warn(typeof(SamplePointTable).Name, "Upgrading database from version "
+ oldVersion + " to " + newVersion
+ ", which will destroy all old data");
database.ExecSQL("DROP TABLE IF EXISTS " + TABLE_SAMPLE_POINT);
OnCreate(database);
}