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
C# SQLite数据库插入错误约束_C#_Sqlite_Windows Store Apps - Fatal编程技术网

C# SQLite数据库插入错误约束

C# SQLite数据库插入错误约束,c#,sqlite,windows-store-apps,C#,Sqlite,Windows Store Apps,我正在进行一个web服务调用,该调用返回一个包含50个数据包的消息bean。然后,我按照以下方式将其放入SQLite public void DashboardHandler(Array Bean, long cNum) { foreach (invoiceSummaryBean ib in Bean) { var dash = new dashboardCustomer {

我正在进行一个web服务调用,该调用返回一个包含50个数据包的消息bean。然后,我按照以下方式将其放入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; }


}
当它试图插入时崩溃,说{“Constraint”}


不知道问题出在哪里。我需要全部50个数据包才能插入到表中。

我解决了这个问题。我必须改变表格的创建方式。奇怪的是,每次插入新数据时都必须重新创建它。

我不是100%确定,但您可能需要将dashboardCustomer中的属性标记为列。在许多sqlite数据库系统中,如sqlite net(不是您使用的语法错误的系统),您可以执行类似于_connection.CreateTable()的操作;这不会创建新表,它所做的是确保它存在,或者在它不存在时创建它。