Esempio n. 1
0
        /// <summary>
        /// 执行不返回结果集带参数的SQL语句
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="param">可变个数的参数</param>
        /// <returns>提示信息类</returns>
        public AlertMessage ExecuteNonQuery(string sql, params SQLiteParameter[] param)
        {
            var result = new AlertMessage();

            _conn.Open();
            var trans = _conn.BeginTransaction();

            try
            {
                using (var mycommand = new SQLiteCommand(sql, _conn, trans))
                {
                    mycommand.CommandTimeout = 180;
                    mycommand.Parameters.AddRange(param);
                    mycommand.ExecuteNonQuery();
                    trans.Commit();
                    result.IsSuccess = true;
                }
            }
            catch (Exception e)
            {
                trans.Rollback();
                result.IsSuccess = false;
                result.AddMsg(e.Message);
            }
            finally
            {
                _conn.Close();
            }

            return(result);
        }