Hello,
Firstly, here is a document about Xamarin.Forms Local Databases(Sqlite) - Xamarin | Microsoft Learn. Here is a demo about SQLite, you can download and test it.
I just want to learn how I can get my values to display on a page from a database without typing them manually
Next, if you have tested above sqlite demo, you will find on data in DB, please open TodoListPage.cs
and find OnAppearing
method. You can add items with code when the DB is empty like following code.
protected override async void OnAppearing()
{
base.OnAppearing();
TodoItemDatabase database = await TodoItemDatabase.Instance;
List<TodoItem> todoItems= await database.GetItemsAsync();
if (todoItems == null || todoItems.Count == 0) {
for (int i = 0; i < 10; i++)
{
//Add items with code when List is empty
await database.SaveItemAsync(new TodoItem() { Name=i.ToString(), Notes="this Note"+i});
}
}
todoItems=await database.GetItemsAsync();
listView.ItemsSource = todoItems.OrderByDescending(item => item.ID).ToList();
}
then I can learn how to increase/decrease the products based on the user values.
For example, I want the increase the products based on the User ID, we can use .OrderBy(item => item.ID)
like following code
todoItems.OrderBy(item => item.ID).ToList();
Decreasing the products based on the User ID like following code.
todoItems.OrderByDescending(item => item.ID).ToList();
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.