搜索Android c# Xamarin Sqlite数据库

本文关键字:Sqlite 数据库 Xamarin Android 搜索 | 更新日期: 2023-09-27 18:11:31

我需要一些帮助来弄清楚如何搜索我的SQLite数据库。我试图寻找他们的蛋糕和星星;这是我的连接:

// Create our connection
string folder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var db = new SQLiteConnection(System.IO.Path.Combine(folder, "OnTopFiles.db"));
db.CreateTable<User>();
// Insert note into the database
var note = new User { cake = "frosting marble", stars = "5" };
db.Insert(note);
// Show the automatically set ID and message.
Console.WriteLine("{0}: {1}", note.cake, note.stars);

搜索Android c# Xamarin Sqlite数据库

您可以使用WHERE查询:

var query = conn.Table<User>().Where(u => u.Cake.StartsWith("frosting"));
foreach (var user in query)
{
    // Use user.cake or other properties
}

或者,您可以直接使用SQL。您正在使用的库隐藏了SQLite SQL,因此大多数SQLite语法对您隐藏。这个库是纯。net标准的,可以在所有Xamarin平台上运行。您拥有SQL的全部功能,因此搜索与其他平台相同。

https://github.com/MelbourneDeveloper/SQLite.Net.Standard