Hello, need example to read data from online database (MS SQL OR MYSQL) to list view.
Simple example
NOT LOCAL DATABASE EXAMPLES, CLOUD HOSTED
Thank you
Hello, need example to read data from online database (MS SQL OR MYSQL) to list view.
Simple example
NOT LOCAL DATABASE EXAMPLES, CLOUD HOSTED
Thank you
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Tahir AnsariRank #366 · 6.8K reputationPosted Oct 27, 2023, 9:19 AM EDT
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() { InitializeComponent(); GetDataFromDatabase(); } async void GetDataFromDatabase() { string connectionString = "Server=yourserver;Database=yourdatabase;Uid=yourusername;Pwd=yourpassword;"; using (MySqlConnection connection = new MySqlConnection(connectionString)) { try { await connection.OpenAsync(); string query = "SELECT YourColumnName FROM YourTable"; using (MySqlCommand cmd = new MySqlCommand(query, connection)) using (MySqlDataReader reader = cmd.ExecuteReader()) { List data = new List(); while (await reader.ReadAsync()) { data.Add(new YourDataModel { YourColumnName = reader["YourColumnName"].ToString() }); } dataListView.ItemsSource = data; } } catch (Exception ex) { // Handle any exceptions Console.WriteLine(ex.Message); } } } } public class YourDataModel { public string YourColumnName { get; set; } } }