SQL Compact select top 1

前端 未结 5 1527
不知归路
不知归路 2021-02-19 12:56

While porting an application from SQL 2005 to SQL Server Compact Edition, I found that I need to port this command:

SELECT TOP 1 Id FROM tblJob WHERE Holder_Id I         


        
5条回答
  •  半阙折子戏
    2021-02-19 13:24

    This is slightly orthogonal to your question.

    SQL Server Compact Edition actually doesn't perform very well with SQL queries. You get much better performance by opening tables directly. In .NET, you do this by setting the command object's CommandText property to the table name, and the CommandType property to CommandType.TableDirect.

    If you want to filter the results, you will need an index on the table on the column(s) you want to filter by. Specify the index to use by setting the IndexName property and use SetRange to set the filter.

    You can then read as many or as few records as you like.

提交回复
热议问题