SQL Compact select top 1

老子叫甜甜 提交于 2019-12-04 00:24:52
Robinb
SELECT TOP(1) Id 
FROM tblJob 
WHERE Holder_Id IS NULL

Need the brackets as far as I know.

reference: http://technet.microsoft.com/en-us/library/bb686896.aspx

addition: likewise, only for version 3.5 onwards

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.

I've used Fill method of SqlCEDataAdapter. You can do:

DbDataAdapter.Fill (DataSet, Int32, Int32, String) Adds or refreshes rows in a specified range in the DataSet to match those in the data source using the DataSet and DataTable names. Supported by the .NET Compact Framework.

http://msdn.microsoft.com/en-ie/library/system.data.common.dbdataadapter.fill(v=VS.80).aspx

Looks like it can't be done in compact. You have to read all the jobs, or make a SqlReader, and just read the first one.

Well found a reason. Management studio carries and uses it's own version od SQL Server Compact. See more in http://en.wikipedia.org/wiki/SQL_Server_Compact.

SQL Server Management Studio 2005 can read and modify CE 3.0 and 3.1 database files (with the latest service pack), but the SQL Server Management Studio 2008 from the "Katmai" 2008 CTP release (or later) is required to read version 3.5 files.

The RTM of SQL Server Management Studio 2008 and Microsoft Visual Studio Express 2008 SP1 can create, modify and query CE 3.5 SP1 database files.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!