How to use FETCH in OleDb query?

Viewed 16

I have xlsx table like this:

Name           SubDatasetCount   Parameter1    Parameter2   ParameterX .......
Dataset1
SubDataset1
SubDataset2
SubDatasetX

Dataset2
SubDataset1
SubDataset2
SubDatasetX
.
.
.

My goal is to load any Dataset Parameters and all its SubDatasets.

Xlsx format and reading method is given. At this moment I read Data1-SubDataCount and then I try to run following SQL query for OleDbReader:

SELECT *
FROM ["SheetName"$]
WHERE Name LIKE '%DatasetName%'
FETCH NEXT [SubDatasetCount] ROWS ONLY

It cause OleDbException: 'IErrorInfo.GetDescription failed with E_FAIL(0x80004005).' . Prior addition of FETCH query worked fine. I have no SQL knowledge, I copied it from here: How to select next rows from database in C#?

In linked answer there is statement that ORDER BYis a MUST, but I can not do that obviously. And even when I tested following query, error is same:

SELECT *
FROM ["SheetName"$]
WHERE Name LIKE '%DatasetName%'
ORDER BY Name
FETCH NEXT 10 ROWS ONLY

It works when I remove FETCH and leave ORDER BY. Quick study of that specific error yields always same result - reserved keyword is used in the query. But I don't see anything like that in FETCH part of query.

  1. How do I make FETCH work?
  2. In case FETCH is fixed somehow, how to solve ORDER BY requirement? ORDER BY(SELECT NULL) cause exception.
0 Answers
Related