SQLite数据库插入错误约束
问题描述:
我正在做一个Web服务调用,它返回一个包含50个数据包的消息bean。然后,我把它放到我的SQLite以下方式SQLite数据库插入错误约束
public void DashboardHandler(Array Bean, long cNum)
{
foreach (invoiceSummaryBean ib in Bean)
{
var dash = new dashboardCustomer
{
actualUsage = ib.actualUsage,
serviceCost = ib.serviceCost,
mmbtu = ib.mmbtu,
OptiServiceCost = ib.optimizedServiceCost,
period = ib.period,
periodType = ib.periodType,
service = ib.service,
serviceType = ib.serviceType,
measure = ib.unitOfMeasure,
customerNumber = cNum
};
try
{
db.insertDashboard(dash);
}
catch
{
}
}
}
我的插入方法
public async Task insertDashboard(dashboardCustomer d)
{
try
{
await db.InsertAsync(d);
}
catch(SQLiteException)
{
throw;
}
}
我的表
[Table("dashboardCustomer")]
public class dashboardCustomer
{
public long customerNumber { get; set; }
public int period { get; set; }
public string periodType { get; set; }
public string service { get; set; }
public double actualUsage { get; set; }
public double mmbtu { get; set; }
public double OptiServiceCost { get; set; }
public double serviceCost {get; set;}
public string serviceType { get; set; }
public string measure { get; set; }
}
当它试图插入它崩溃说{ “约束”}?
不知道是什么问题。我需要将所有50个数据包插入表中。
答
我想出了这个问题。我不得不改变表格的创建方式。奇怪的是,每次插入新数据时都必须重新创建。
+0
在许多sqlite数据库系统中,如sqlite-net(不是你正在使用的语法),你可以使用_connection.CreateTable
我不是100%确定,但您可能需要将dashboardCustomer中的属性标记为列。 –