Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi my friends,

I have a database on "SQL Compact Edition 3.0". And I cant upgrade it to new version. I want to get row count from some record that i select and as default this version of sql ce does not support.

So, How can I simulate RowCount in "Sql CE 3.0"?

I tried a lot of way for resolve this issue but my solutions didn't works well.

Thanks for your help. I waiting for them :-)
Posted
Updated 2-Jan-12 2:31am
v3
Comments
DaveAuld 2-Jan-12 8:40am    
"I want to get row count from some record", that would be 1 then ???? Do you mean table? or do you mean you want the rowcount for a returned query? Please update the question and clarify. Thanks.

I'm not sure what RowCount has to do with the record you just inserted - if you inserted it you know how many of it there is...

But to get the RowCount in SqlCE is as easy as it is in MsSql:
SQL
SELECT COUNT(*) FROM MyTable


If this isn't what you are after, what is the problem you are having, exactly?


":). Yah, its really angry me.
I tried Top at first but, The SQL CE 3.0 does not support "Top" function :(
I use this code:

define @a = 20 --@a is a variable ;)
if(SELECT COUNT(*) FROM table WHERE id BETWEEN 10 AND a<10)
{
  -- @a++
}


But there is a problem. How to make a loop in SQL?"


I had forgotten that TOP was introduced in V3.5! :O

To be honest, I'm not sure I would bother.
Bearing in mind that SQLCE is single user, and all the resources used are local to your PC (or other equipment), it makes no odds particularly if you retrieve all the records and filter them locally. Or at least retrieve all the IDs into an array and then request just the relevant records. (SQLCE is not very efficient when it comes to complex queries at the best of times)

What are you trying to use the DB on?
 
Share this answer
 
v2
Comments
mhd.rad 2-Jan-12 9:04am    
Thanks for your answer, but it just count all of my database. I want to get records between two ID. Look at this:

SELECT * FROM table where id between 10 and 20.

I want to select 10 Query from bank and this select query works well. But if I was removed some record from bank it maybe show me 9 records or less.
Exactly I want to use RowCount for Lazy Loading. Thanks
OriginalGriff 2-Jan-12 9:14am    
Ah! Paging data in SQLCE == PITA! :laugh:
Have you considered
SELECT TOP(10) * FROM MyTable WHERE id > 10
mhd.rad 2-Jan-12 14:17pm    
:). Yah, its really angry me.
I tried Top at first but, The SQL CE 3.0 does not support "Top" function :(
I use this code:

define @a = 20 --@a is a variable ;)
if(SELECT COUNT(*) FROM table WHERE id BETWEEN 10 AND a<10)
{
-- @a++
}

But there is a problem. How to make a loop in SQL?
OriginalGriff 2-Jan-12 14:36pm    
Answer updated
Try modifying the query to use correlated sub-query. Something like:
SQL
SELECT ...
FROM YourTable yt
WHERE 10 > (SELECT COUNT(*)
             FROM YourTable yt2
             WHERE yt2.Id < yt.Id)
That should bring you the first 10.
If you want to go further in pages add necessary where conditions (Id > greatest value this far)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900