SQLBulkCopy inserts a new row with NULL values for all columns

点点圈 提交于 2019-11-29 16:59:57

You could change your query to skip empty rows in excel:

"SELECT * FROM [" + Path.GetFileName(excelPath) + "] WHERE [Employee] IS NOT NULL"

This should avoid that empty rows are added to the DataTable. Of course you could also remove them later but it would be less efficient. For example:

dtExcelData = dtExcelData.AsEnumerable()
    .Where(r => !String.IsNullOrEmpty(r.Field<string>("Employee")))
    .CopyToDataTable();
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!