Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

C# script component, load data from flat file

$
0
0

I have a flat file like this:

I need to load it into DB with column names:

 REASON        OrderNum         RemitAmt         PayMethod          HTC          FirstName         LastName          AddressLine1                   City         State          ZipCode         HomePhone          WorkPhone               PO#         OX#          DISC1         DISC2         

I think one way I can do is using C# but I don’t know how to load into table with each line more than one columns. If each line only has one column I can do something like(set flat file input as one column and skip first four lines):

publicoverridevoid Input0_ProcessInputRow(Input0Buffer Row)

   {

       string ColumnName;

       string ColumnValue;

       string line = Row.Column0.ToString().Trim();

       // Check for an empt row

       if (line.Length > 0)

       {

           ColumnName = line.Substring(0, Row.Column0.IndexOf(":"));

           // check for an empty valllue after the colon

           if (line.Substring(Row.Column0.IndexOf(":")).TrimEnd().Length> 1)

           // Extract the column value from after the colon and space

           {

               ColumnValue = Row.Column0.Substring(Row.Column0.IndexOf(":")).Trim();

               switch (ColumnName)

                   {

                       case"REASON":

                       // The Reason value indicates a new record

                       Output0Buffer.AddRow();

                       Output0Buffer.Reason = ColumnValue;

                       break;

                   case"OrderNum":

                       Output0Buffer.OrderNum = ColumnValue;

                       break;

                   case"Name":

                       Output0Buffer.Name = ColumnValue;

                       break;

                   case"Address":

                       Output0Buffer.Address = ColumnValue;

                       break;

               }

           }

       }

// Not sure where the following code should go

  if (line.Contains("---"))

       {

           break;

       }

       if (line.Contains("*******"))

       {

           return;

       }

   }

Please help

Thank you.


Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>