List SQLite给出了例外

List SQLite给出了例外,list,sqlite,error-handling,insert,catch-block,List,Sqlite,Error Handling,Insert,Catch Block,我正在努力将项目列表添加到数据库中,我希望在添加更多项目时不断添加个人数据。这是我的密码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using StockTakeRedo.BL; using System.Data.SQLite; using System.Data; namespace StockTakeRedo.DAL { class PersonSQ

我正在努力将项目列表添加到数据库中,我希望在添加更多项目时不断添加个人数据。这是我的密码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StockTakeRedo.BL;
using System.Data.SQLite;
using System.Data;

namespace StockTakeRedo.DAL
{
    class PersonSQLProvider : PersonProviderBase
    {
        private SQLiteConnection _sqlConnection;
        private string _connStr = "Data Source=c:\\DataStores\\PersonItemDatabase.s3db;Version=3";


        public override int Insert(Person Person, List<Item> ItemList)
        {
            int rc = 0;

            try
            {



                _sqlConnection = new SQLiteConnection(_connStr);
                _sqlConnection.Open();

                string insertQuery = "INSERT INTO PersonItemDatabase([_ID], [_Age], [_Email], [_FirstName], [_LastName], [_ItemName], [_ItemCode], [_ItemPrice], [_ItemDescription]) VALUES(" +
                                     "@ID, @Age, @Email, @FirstName, @LastName, @ItemName, @ItemCode, @ItemPrice, @ItemDescription)";
                foreach (Item item in ItemList)
                {


                    SQLiteCommand sqlCommand = new SQLiteCommand(insertQuery, _sqlConnection);
                    SQLiteParameter[] sqlParams = new SQLiteParameter[]
                    {
                    new SQLiteParameter("@ID",DbType.Int64),
                    new SQLiteParameter("@Age", DbType.Int32),
                    new SQLiteParameter("@Email",DbType.String),
                    new SQLiteParameter("@FirstName",DbType.String),
                    new SQLiteParameter("@LastName",DbType.String),
                    new SQLiteParameter("@ItemName", DbType.String),
                    new SQLiteParameter("@ItemCode", DbType.Int32),
                    new SQLiteParameter("@ItemPrice", DbType.Int32),
                    //new SQLiteParameter("@Quantity",DbType.Int32),
                    new SQLiteParameter("@ItemDescription",DbType.String)
                    };

                    sqlParams[0].Value = Person.ID;
                    sqlParams[1].Value = Person.Age;
                    sqlParams[2].Value = Person.Email;
                    sqlParams[3].Value = Person.FirstName;
                    sqlParams[4].Value = Person.LastName;
                    sqlParams[5].Value = item.ItemName;
                    sqlParams[6].Value = item.ItemCode;
                    sqlParams[7].Value = item.ItemPrice;
                    sqlParams[8].Value = item.ItemDescription;

                    sqlCommand.Parameters.AddRange(sqlParams);
在rc=sqlCommand.ExecuteNonQuery()之后;它跳转到此捕捉块的行:

            catch (SQLiteException ex)
            {
                if (ex.ErrorCode == SQLiteErrorCode.Constraint)
                {
                    rc = -1;
                }
                else
                {
                    throw ex;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return rc;
        }
    }
}

没关系,我做对了,我把数据库中的id设置为主键,我更改了它,然后它添加了所有数据

            catch (SQLiteException ex)
            {
                if (ex.ErrorCode == SQLiteErrorCode.Constraint)
                {
                    rc = -1;
                }
                else
                {
                    throw ex;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return rc;
        }
    }
}