Xamarin Forms sqlite 选择特定行 [英] Xamarin Forms sqlite Select specifics rows

查看:46
本文介绍了Xamarin Forms sqlite 选择特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Xamarin 的新手,我正在寻找一种方法来选择表格中的特定行.

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

这是我的方法:

 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();
            }

这是有效的,但问题是,如果您删除 ID 介于 10 和 17 之间的 3 行,您将不会得到 7 行,而是 4 ( (17-10)= 7 和 (7-3) =4) .

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

所以我正在寻找一种即使删除行也能获得 7 行的方法.或者,如果您知道更好的解决方案.

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

我在想,也许有一种方法可以刷新我的 word.ID,那么这将始终有效.

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

谢谢

推荐答案

如果你想让它总是在索引 10 之后取接下来的七个元素,你可以像这样进行查询:

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();

请记住,如果您创建了一个包含 17 个项目的表,然后删除了 ID 为 12-16(5 个项目)的项目,然后再添加了五个项目,这将返回 ID 为 10、11、17-21 的项目. 它不会重新分配 id

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

这篇关于Xamarin Forms sqlite 选择特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆