I am working on a fix for a C # project that uses an Excel worksheet with data definition to create the .fmt file used by bulk insert in SQL Server.
My problem is that Excel files sometimes have empty lines at the bottom, and the C # handler I'm working on finds a series of lines that exceed the actual number of lines containing the data definition.
Therefore, the fmt file has a larger number of lines on its second line, and the bulk insert throws an exception when it reaches the bottom and tries to read.
For example, there are only 50 rows of data and 50 blank lines. The fmt file will have 100 on the second line (first line for the version of SQL Server). Lines 3 through 52 are 50 lines of data definition. When a massive insert tries to reach row 53, it returns the number of column exceptions.
The C # parser uses Ace OleDB 12 to connect to an Excel 97 file.
SQL:
var commandText = string.Format("SELECT * FROM [{0}$]", SpreadSheetName);
I tried adding a WHERE clause to the SQL code to select only rows with a non-empty column "A", but this will not work.
SELECT * FROM [{0}$] WHERE [A] <> ''
Is there a way that command text can be improved with some SQL code to retrieve only rows of data from Excel where a certain condition is met?
source share