hugo
hugo

Reputation: 475

Xamarin Forms sqlite Select specifics rows

I am a novice in Xamarin and I am looking for a way so select specifics rows in my table.

Here is my methode :

 public List<MyWords> SelectWords( int rows  , int x )
        {

            if ( x<=6 ) {
                var myword = (from word in conn.Table<MyWords>()
                              where ( word.ID >= 10 && word.ID =< 17 )
                              select word);
                return myword.ToList();
            }

This is working but the things is, if you delete 3 rows which ID is between 10 and 17 , you will not get 7 rows but 4 ( (17-10)= 7 and (7-3) =4) .

So I am looking for a way to get 7 rows even if I delete rows . Or if you know a better solution.

I was thinking , maybe there is a way to refresh my word.ID then this will always work .

thanks

Upvotes: 0

Views: 817

Answers (1)

cvanbeek
cvanbeek

Reputation: 1961

If you wanted to make it so that you always took the next seven elements after the index ten, you could make your query something like this:

return conn.Table<MyWords>().Where(x => x.id >= 10).Take(7).ToList();

Keep in mind that if you created a table with 17 items, and then deleted the items with ids 12-16 (5 items) and then added five more items, this would return items with ids 10, 11, 17 - 21. It doesn't reassign ids

Upvotes: 1

Related Questions