Ejemplo n.º 1
0
        public override bool Import(DataTable Data, ODAParameter[] Prms)
        {
            DataTable  ImportData = Data.Copy();
            IDbCommand Cmd        = OpenCommand();

            try
            {
                AseBulkCopy sqlbulkcopy = new AseBulkCopy((AseConnection)Cmd.Connection);
                for (int i = 0; i < Prms.Length; i++)
                {
                    if (ImportData.Columns.Contains(Prms[i].ParamsName))
                    {
                        AseBulkCopyColumnMapping colMap = new AseBulkCopyColumnMapping(ImportData.Columns[i].ColumnName, Prms[i].ParamsName);
                        sqlbulkcopy.ColumnMappings.Add(colMap);
                    }
                }
                sqlbulkcopy.BulkCopyTimeout = 600000;
                //需要操作的数据库表名
                sqlbulkcopy.DestinationTableName = ImportData.TableName;
                //将内存表表写入
                sqlbulkcopy.WriteToServer(ImportData);
                sqlbulkcopy.Close();
                return(true);
            }
            finally
            {
                CloseCommand(Cmd);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Bulk copies a set of objects to the server.
        /// </summary>
        /// <param name="connection">The connection to use.</param>
        /// <param name="tableName">The name of the table.</param>
        /// <param name="reader">The reader to read objects from.</param>
        /// <param name="configure">A callback method to configure the bulk copy object.</param>
        /// <param name="options">Options for initializing the bulk copy object.</param>
        /// <param name="transaction">An optional transaction to participate in.</param>
        public override void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action <InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            AseBulkCopyOptions aseOptions = AseBulkCopyOptions.Default;

            if (options.HasFlag(InsightBulkCopyOptions.CheckConstraints))
            {
                aseOptions |= AseBulkCopyOptions.CheckConstraints;
            }
            if (options.HasFlag(InsightBulkCopyOptions.FireTriggers))
            {
                aseOptions |= AseBulkCopyOptions.FireTriggers;
            }
            if (options.HasFlag(InsightBulkCopyOptions.KeepIdentity))
            {
                aseOptions |= AseBulkCopyOptions.KeepIdentity;
            }
            if (options.HasFlag(InsightBulkCopyOptions.KeepNulls))
            {
                aseOptions |= AseBulkCopyOptions.KeepNulls;
            }
            if (options.HasFlag(InsightBulkCopyOptions.TableLock))
            {
                aseOptions |= AseBulkCopyOptions.TableLock;
            }
            if (options.HasFlag(InsightBulkCopyOptions.UseInternalTransaction))
            {
                aseOptions |= AseBulkCopyOptions.UseInternalTransaction;
            }

            using (var bulk = new AseBulkCopy((AseConnection)connection, aseOptions, (AseTransaction)transaction))
                using (var insightBulk = new SybaseAseInsightBulkCopy(bulk))
                {
                    bulk.DestinationTableName = tableName;

                    // map the columns by name, in case we skipped a readonly column
                    foreach (DataRow row in reader.GetSchemaTable().Rows)
                    {
                        bulk.ColumnMappings.Add(new AseBulkCopyColumnMapping((string)row["ColumnName"], (string)row["ColumnName"]));
                    }

                    if (configure != null)
                    {
                        configure(insightBulk);
                    }
                    bulk.WriteToServer(reader);
                }
        }
		/// <summary>
		/// Bulk copies a set of objects to the server.
		/// </summary>
		/// <param name="connection">The connection to use.</param>
		/// <param name="tableName">The name of the table.</param>
		/// <param name="reader">The reader to read objects from.</param>
		/// <param name="configure">A callback method to configure the bulk copy object.</param>
		/// <param name="options">Options for initializing the bulk copy object.</param>
		/// <param name="transaction">An optional transaction to participate in.</param>
		public override void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action<InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
		{
			AseBulkCopyOptions aseOptions = AseBulkCopyOptions.Default;
			if (options.HasFlag(InsightBulkCopyOptions.CheckConstraints))
				aseOptions |= AseBulkCopyOptions.CheckConstraints;
			if (options.HasFlag(InsightBulkCopyOptions.FireTriggers))
				aseOptions |= AseBulkCopyOptions.FireTriggers;
			if (options.HasFlag(InsightBulkCopyOptions.KeepIdentity))
				aseOptions |= AseBulkCopyOptions.KeepIdentity;
			if (options.HasFlag(InsightBulkCopyOptions.KeepNulls))
				aseOptions |= AseBulkCopyOptions.KeepNulls;
			if (options.HasFlag(InsightBulkCopyOptions.TableLock))
				aseOptions |= AseBulkCopyOptions.TableLock;
			if (options.HasFlag(InsightBulkCopyOptions.UseInternalTransaction))
				aseOptions |= AseBulkCopyOptions.UseInternalTransaction;

			using (var bulk = new AseBulkCopy((AseConnection)connection, aseOptions, (AseTransaction)transaction))
			using (var insightBulk = new SybaseAseInsightBulkCopy(bulk))
			{
				bulk.DestinationTableName = tableName;
				if (configure != null)
					configure(insightBulk);
				bulk.WriteToServer(reader);
			}
		}
		/// <summary>
		/// Bulk copies a set of objects to the server.
		/// </summary>
		/// <param name="connection">The connection to use.</param>
		/// <param name="tableName">The name of the table.</param>
		/// <param name="reader">The reader to read objects from.</param>
		/// <param name="configure">A callback method to configure the bulk copy object.</param>
		/// <param name="options">Options for initializing the bulk copy object.</param>
		/// <param name="transaction">An optional transaction to participate in.</param>
		public override void BulkCopy(IDbConnection connection, string tableName, IDataReader reader, Action<InsightBulkCopy> configure, InsightBulkCopyOptions options, IDbTransaction transaction)
		{
			if (reader == null) throw new ArgumentNullException("reader");

			AseBulkCopyOptions aseOptions = AseBulkCopyOptions.Default;
			if (options.HasFlag(InsightBulkCopyOptions.CheckConstraints))
				aseOptions |= AseBulkCopyOptions.CheckConstraints;
			if (options.HasFlag(InsightBulkCopyOptions.FireTriggers))
				aseOptions |= AseBulkCopyOptions.FireTriggers;
			if (options.HasFlag(InsightBulkCopyOptions.KeepIdentity))
				aseOptions |= AseBulkCopyOptions.KeepIdentity;
			if (options.HasFlag(InsightBulkCopyOptions.KeepNulls))
				aseOptions |= AseBulkCopyOptions.KeepNulls;
			if (options.HasFlag(InsightBulkCopyOptions.TableLock))
				aseOptions |= AseBulkCopyOptions.TableLock;
			if (options.HasFlag(InsightBulkCopyOptions.UseInternalTransaction))
				aseOptions |= AseBulkCopyOptions.UseInternalTransaction;

			using (var bulk = new AseBulkCopy((AseConnection)connection, aseOptions, (AseTransaction)transaction))
			using (var insightBulk = new SybaseAseInsightBulkCopy(bulk))
			{
				bulk.DestinationTableName = tableName;

				// map the columns by name, in case we skipped a readonly column
				foreach (DataRow row in reader.GetSchemaTable().Rows)
					bulk.ColumnMappings.Add(new AseBulkCopyColumnMapping((string)row["ColumnName"], (string)row["ColumnName"]));

				if (configure != null)
					configure(insightBulk);
				bulk.WriteToServer(reader);
			}
		}