Excel file request with C #, question with numeric cells

I am requesting an Excel file to retrieve data and display it in a monitoring tool. The fact is that whenever I try to select a record with its identifier, with the following query, it gives an error when executing the query:

ExecuteCommandTextErrorHandling

will report that the request type and target cell are incompatible.

My request looks like

SELECT TOP 20 [Fields...] 
FROM [RECORD$] 
WHERE (([id] = '1'))

The id column can contain more than just numbers, so its cell type is the default standard type, which is the standard one.

My question is : how can I take a record without knowing its type before?

Do I need to force a column type, if so, how? Should I catch the exception and try again without quotes?

, Excel

 public static DataTable queryXlsFile(String query, OleDbConnection dbConnection)
 {
        OleDbDataAdapter dbCommand = new OleDbDataAdapter(query, dbConnection);
        DataTable dt = new DataTable();
        dbCommand.Fill(dt);
        return dt;
    }

Provider=Microsoft.ACE.OLEDB.12.0; data source=C:\\test\\321.xls; Extended Properties=\"Excel 8.0;HDR=Yes;\";

.

+3
2

IMEX = 1;

HDR = Yes; IMEX = 1"

+1

, , , - .

+1

All Articles