Skip to content

Sqlbulkcopy and column maping class C#

j c

Asked Jun 30, 2014, 1:33 PM EDT1 answer
Share
LinkedInX
I have metadata table that contain source columns/tables and destination columns
and tables information and their column mapping information

SourceTable
SourceTableID SourceTableName
1                      ProductA
2                      ProductB

3   ProductC
SourceTableColumnn table
SourceTableColumnID SourceTableID SourceTableColumnName
1                                     1                              Name
2                                     1                              Color
3                                     1                              Size
4                                     2                              Quality
5                                     3                               Quantity

 DestinationTable
DestinationTableID  DestinationTableName
1                                ProductA
2                                ProductB
3                                ProductC

DestinationTableColumnn table
DestinationTableColumnID DestinationTableID DestinationTableColumnName
1                                                1                               Name
2                                                1                               Color

3                                                1                               Size
4                                                2                               Quality
5                                                3                               Quantity

And
SourcDestinationColumnMapping  Table
SourceTableColumnID    DestinationTableColumnID
1                                         1
2                                         2
3                                         3
4                                         4
5                                         5

I would like to dynamically ( setting data connection and mapping the column / table )  load data from source to destination table based on
this metadata table using sqlbulkcopy and columnmaping class (C#) since there
will be many tables and each table will have different columns.
How can I do this in C#? can you show me some examples?

Thanks


 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    This is ETL job which you're trying to do. 

    Generic rule is to solve problem right you need right set of tools. 

    You could do in C# but I suggest you to use SQL Server, SSIS to handle this thing.

    You can right any stored procedure or trigger at particular action to achieve this.

    Let me know if you've really strong opinion to handle it via C#

    twitter @sumitjolly
    0