首页 > 解决方案 > 选择 ID 匹配 int 数组的 SQLite.NET 记录

问题描述

我正在使用 SQLite.NET。我正在尝试将整数数组传递给搜索查询。我想返回 ID(表属性)与数组中的整数匹配的记录列表。数组大小为 10。

在 MainPage.cs 中:

int[] arr  = new int[10];
// for testing purposes    
for (int i = 0; i <= 9; i++{
  arr[i] = i;
}

var selected = App.Database.SearchList(arr);

在 SQLiteDatabase.cs 中:

public List<Rooms> SearchList(int[] ID)
{
     return database.Query<Rooms>("SELECT * FROM Rooms WHERE ID = ?;", ID);
}

这会在执行查询时导致以下错误:

System.NotSupportedException:超时获取异常详细信息

如何返回 ID 匹配的记录列表?谢谢你。

标签: c#sqlitexamarinxamarin.forms

解决方案


使用IN关键字

WHERE ID IN (1, 2, 3, 4, 5)

推荐阅读