Esempio n. 1
0
        public DatabaseInsertData(ConnectionConfig config, DatabaseInterface database, String
                                  TableName)
        {
            _connectionConfig = config;
            _database         = database;

            sql = new InsertDBCommandBuilder((DatabaseType)Enum.Parse(typeof(DatabaseType), config.DBType));

            if (!String.IsNullOrEmpty(TableName))
            {
                sql.TableName = TableName;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// insert many new data
        /// 插入多个新数据
        /// </summary>
        /// <param name="ColumnName"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        public Int32 ExecueTransactionCommand(string[] ColumnName, List <object[]> Value)
        {
            var InsertBatch = "";

            for (var i = 0; i < Value.Count; i++)
            {
                InsertDBCommandBuilder sql1 = new InsertDBCommandBuilder();
                sql1.TableName = sql.TableName;
                sql1.AddInsertColumn(ColumnName, Value[i]);

                InsertBatch += sql1.BuildCommand() + ";";
            }

            //数据库连接
            if (_connectionConfig.IsAutoCloseConnection == false)
            {
                if (_database.CheckStatus() == false)
                {
                    throw new Exception("databse connect not open");
                }
            }

            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Open();
            }

            var result = _database.ExecueTransactionCommand(new String[] { InsertBatch }, _connectionConfig.WaitTimeout);

            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Close();
            }


            return(result);
        }