0

I have a application in which i am taking the csv file and dumping to data base in the respective table.
Problem is if column data does not match
Then it gives the following error
Column in the source data doesnot match with destination columns
For this i am handling, that is i am creating the error log file
which will contain the unmatched column data.
Following is the code:

while (!sr.EndOfStream)
{
value = sr.ReadLine().Split(',');
                    
if (value.Length == dt.Columns.Count)
{
         row = dt.NewRow();
         row.ItemArray = value;
         dt.Rows.Add(row);
}
else
{
         SW.WriteLine(value);
}
}   //End Of while

I have one csv file it contain the proper data with 7 column
And data is inserting in the table properly
But for testing purpose i am adding one column in the data
And this column should go in the err file
And when i am debugging the code it give same column heading as column data
And while writing to server it gives error
Data in the Datasource does not match with the destination table
Not getting what to do

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Mitja Bonca
0

You can simple use a StreamWriter object in the else block

using (StreamWriter sw = File.AppendText(@"C:\1\log_1.txt"))
            {
                sw.WriteLine(value);
            }

Edited by Mitja Bonca: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.