Return Records From SqlBulkCopy using IDataReader

c# entity-framework sqlbulkcopy sql-server


I'm using the SqlBulkCopy class to bulk update and insert data into my database. I want to apply additional logic to the data after it has been modified or entered.

My IDataReader has to be updated and inserted with a variety of records right now. Any operations to the database are successful. However, the IDataReader object has no rows left after the data is written.

Is it possible to save the rows with the automatically created Unique Identifier field for the entered records?

This is a portion of my code:

    public IDataReader DoBulkCopy<T>(List<T> DataToInsert, string DestinationTableName)
        var BulkCopy = new SqlBulkCopy(ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString, SqlBulkCopyOptions.KeepNulls);
        BulkCopy.BulkCopyTimeout = 0;
        BulkCopy.BatchSize = 50;
        BulkCopy.DestinationTableName = DestinationTableName;

        IDataReader reader = DataToInsert.AsDataReader();

        return reader;

I appreciate it.

12/8/2012 3:08:43 AM

Accepted Answer

After doing much investigation, I have come to the conclusion that this is not conceivable. I managed to think of a solution. I entered the DateTime myself. Before running the query, call Now() to a variable. I then performed a select query for all records where the LastUpdated timestamp field was higher than the DateTime variable recorded prior to the insert/update after the query had completed.

Please take notice that in my instance, this works well since only this scheduler is allowed to insert or change data into this database. This strategy would need to be rethought or modified if this were an app where the data may originate from several sources or users.

12/11/2012 4:26:37 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow