0

I'm using SqlBulkCopy in order to copy a datatable into a database table, because the data is over 250,000 rows.

But I am facing a problem. I need to make condition for the process of copying data.

For example If The Code Equal '1111' then don't copy this row

I can't write this with SQL query statements like Insert Into because this will take too much time.

Here is my code:

SqlBulkCopy blk = new SqlBulkCopy(myConnectionString);

try
{
    blk.DestinationTableName = "myTable";
    blk.WriteToServer(myDataTable);
}
catch (Exception ex)
{ MessageBox.Show(ex.Message, "System Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }

Please any one can help me :)

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ahmed mohamady
  • 293
  • 1
  • 7
  • 30
  • No I Can't Because "I need to check if The row with Code '1111' is already stored in database table or not" – ahmed mohamady Jun 23 '13 at 09:34
  • and if i will check the datatable row by row it will take too much time – ahmed mohamady Jun 23 '13 at 09:35
  • 2
    The approach is to (1) bulkcopy everything into a staging table, and then (2) from there start applying conditions and do updates etc. The bulkcopy process by design does **not** allow for any conditions, transformations etc. - it just and only **loads** data as quickly as possible – marc_s Jun 23 '13 at 09:42

0 Answers0