Click here to Skip to main content
15,867,954 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My csv file:

empNo | empName
one | John 
2 | Robin 
3 | Thomas

since empNo is not in correct data type and it will not insert in stage table but rest do, Is there any way i can able to catch which line has error data


My code
Try

           sSQL = " BULK INSERT EmpStageTable"
           sSQL += " FROM '" + FullPath + "' "
           sSQL += " WITH ( FIELDTERMINATOR = '|', ROWTERMINATOR = '\n' ) "
           sSQL += " ;select count(*) from EmpStageTable"

           Using cmd As SqlCommand = New SqlCommand(sSQL, cn)
               cmd.ExecuteScalar()
           End Using


What I have tried:

I have no idea how to do it.
I tried to count successful records and total records to find out number of records failed.. but it did not work in all scenarios. 
Posted
Updated 12-Sep-17 6:28am

1 solution

No, there isn't an indication of which row is at fault: you would have to look for yourself and find it. Or better, read the data yourself, process it into valid data only, and pass it as a datatable or similar: SqlBulkCopy.WriteToServer Method (DataTable) (System.Data.SqlClient)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900