How to Limit the Number of Queried Rows in Sqlce
Problem: -In SQLCE 2.0 it is documented that 2 of the common used keywords are not supported in gettings a range of records from a dataset....
https://www.czetsuyatech.com/2021/07/sqlce-limit-queried-rows.html
Problem:
-In SQLCE 2.0 it is documented that 2 of the common used keywords are not supported in gettings a range of records from a dataset. They are LIMIT and TOP which are use this way:
LIMIT:
SELECT * FROM tableA LIMIT 5, 10;
This query will select a recordset from tableA, which will get 10 records starting from the fifth record. So it will return recordset 5 - 15.
TOP:
SELECT TOP 5 * FROM tableA;
The query will return the first 5 records.
Since these keywords are not supported by SQLCE 2.0, I've tried several possible workaround and one that worked for me is using the:
SqlCeDataAdapter.Fill(DataSet ds, int StartRecord, int MaxRecord, String "TableName") method, the parameters are self-explanatory. Using this method you will be able to select a range in your dataset. Example call:
-In SQLCE 2.0 it is documented that 2 of the common used keywords are not supported in gettings a range of records from a dataset. They are LIMIT and TOP which are use this way:
LIMIT:
SELECT * FROM tableA LIMIT 5, 10;
This query will select a recordset from tableA, which will get 10 records starting from the fifth record. So it will return recordset 5 - 15.
TOP:
SELECT TOP 5 * FROM tableA;
The query will return the first 5 records.
Since these keywords are not supported by SQLCE 2.0, I've tried several possible workaround and one that worked for me is using the:
SqlCeDataAdapter.Fill(DataSet ds, int StartRecord, int MaxRecord, String "TableName") method, the parameters are self-explanatory. Using this method you will be able to select a range in your dataset. Example call:
public DataSet QueryAsDataset(string sql, int startRecord, int maxRecord) { DataSet ds = new DataSet(); try { conn.Open(); SqlCeDataAdapter da = new SqlCeDataAdapter(sql, conn); da.Fill(ds, startRecord, maxRecord, "czetsuya"); } catch(SqlCeException e) { LogHelper.WriteLog(ErrorCode.DATABASE_EXECUTE_SQL_DATASET, e.Message); } finally { conn.Close(); } return ds; }
Post a Comment