Click here to Skip to main content
15,846,977 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I have simple Xamarin code to bind data from online db.
Labels are shown.
Between labels are empty.
No data.
Database connection is ok.
Some help?

What I have tried:

MainPage XML CS
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using Xamarin.Forms;

namespace myApp
    public partial class MainPage : ContentPage
        public MainPage()

        async void GetDataFromDatabase()
            string connectionString = 

            using (MySqlConnection connection = 
                   new MySqlConnection(connectionString))
                    await connection.OpenAsync();

                    string query = "SELECT YourColumnName FROM YourTable";
                    using (MySqlCommand cmd = 
                           new MySqlCommand(query, connection))
                    using (MySqlDataReader reader = cmd.ExecuteReader())
                        List<YourDataModel> data = 
                                new List<YourDataModel>();

                        while (await reader.ReadAsync())
                            data.Add(new YourDataModel
                                YourColumnName = 

                        dataListView.ItemsSource = data;
                catch (Exception ex)
                    // Handle any exceptions

    public class YourDataModel
        public string YourColumnName { get; set; }

And add to XML to show data in app:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns=""

        <Label Text="Welcome" TextColor="Black"/>
        <ListView x:Name="dataListView">
                    <TextCell Text="{Binding YourColumnName}" 

        <Label Text="Work label after table binding" 
        TextColor="Blue" />

Updated 5-Nov-23 1:17am
Richard MacCutchan 30-Oct-23 7:02am    
Use the debugger to see how many (if any) records are added to your list.
Stylus STYLUS 30-Oct-23 7:37am    
I check now. Table hae 3 records
Richard MacCutchan 30-Oct-23 7:51am    
Well that does not prove that your code is reading them.
Stylus STYLUS 30-Oct-23 8:02am    
I try to solve that :-)
Dave Kreskowiak 30-Oct-23 10:04am    
If that's your actual code, you should be getting error messages all over the place. Your exception handling code is dumping those errors to Console instead of Debug or Trace.

Comment out the try/catch lines and run it again. Now you should get actual error messages when you run it.

Also, it looks like you copied this code from somewhere and seriously forget to modify it to your database and needs.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900