Ejemplo n.º 1
0
        /// <summary>
        ///  批量新增
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <param name="cols">选择性插入的字段</param>
        /// <returns></returns>
        public bool InsertBatch <T>(List <T> list, string cols, bool needReturn)
        {
            List <CommandInfo> commandInfos = new List <CommandInfo>();

            if (list == null || list.Count <= 0)
            {
                return(false);
            }
            CommandInfo commandInfo = null;
            SqlModel    insertModel = null;

            for (int i = 0; i < list.Count; i++)
            {
                insertModel = CreateSqlHelper.InsertSql(list[i], cols, needReturn);

                commandInfo = new CommandInfo()
                {
                    CommendText = insertModel.Sql,
                    IsProcess   = false,
                    Params      = insertModel.SqlParameters
                };
                commandInfos.Add(commandInfo);
            }
            return(SQLiteHelper.ExecuteTrans(commandInfos));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///  新增
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="cols">选择性插入的字段</param>
        /// <param name="t"></param>
        /// <returns></returns>
        public int Insert <T>(T t, string cols, bool needReturn)
        {
            if (t == null)
            {
                return(0);
            }

            SqlModel insertModel = CreateSqlHelper.InsertSql(t, cols, needReturn);

            if (!needReturn)
            {
                return(SQLiteHelper.ExecuteNonQuery(insertModel.Sql, needReturn, insertModel.SqlParameters));
            }

            object resultObj = SQLiteHelper.ExecuteScalar(insertModel.Sql, false, insertModel.SqlParameters);

            if (resultObj != null && resultObj.ToString() != "")
            {
                return(Convert.ToInt32(resultObj));
            }
            return(0);
        }