Search code examples
c#exceloledb

Select from xls file where row is not null


While reading data from xls file, using oldedb as follows with no problem

OleDbCommand cmd = new OleDbCommand("SELECT * FROM [" + fileID + "]", oledbConn);
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(ds);

But I want to extend the select statement to only select rows of a certain column that is not null WHERE ... IS NOT NULL, what is that ... suppose to be?


Solution

  • If you use the option HDR=YES in your connection string then use the column title in the WHERE clause to specify the column. If not, then use F1...FN to specify the column.

    Select query for HDR=NO (and first column):

    SELECT * FROM [" + fileID + "] WHERE [F1] IS NOT NULL
    

    Select query for HDR=YES:

    SELECT * FROM [" + fileID + "] WHERE [YourColumnTitle] IS NOT NULL