Is it possible to do data type conversion on SQLBulkUpload from IDataReader?

c#-4.0 mapping sqlbulkcopy

Accepted Answer

After everything was said and done, I created a basic wrapper class to house the SQLDataReader and implemented the IDataReader methods just for calling the SQLDataReader method.

Then, while overriding GetValue, search for the column names that require translating while inheriting from the base class:

public override object GetValue(int i)
{
  var landingColumn = GetName(i);
  string landingValue = base.GetValue(i).ToString();

  object stagingValue = null;
  switch (landingColumn)
    {
    case "D4DTE": stagingValue = landingValue.FromStringDate(); break;
    case "D4BRAR": stagingValue = landingValue.ToDecimal(); break;

    default:
        stagingValue = landingValue;
        break;
    }
  return stagingValue;
}

SQLBulkUpload works well, is adaptable, and operates quickly. Although there is a little maintenance burden, nothing actually changes since the source columns seldom change.

0
3/13/2013 6:08:28 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