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

You can simple use a StreamWriter object in the else block

using (StreamWriter sw = File.AppendText(@"C:\1\log_1.txt"))
            {
                sw.WriteLine(value);
            }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.