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
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
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.
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
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.