C# - How To Fill ListBox From MySQL Dataase In C#
__________________________________________________________________________
In CSharp Programming Language .
Source Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace Csharp_And_MySQL
{
public partial class Csharp_ListBox_MySQL : Form
{
MySqlConnection connection = new MySqlConnection("datasource=localhost;port=3306;username=root;password=");
MySqlDataAdapter adapter;
DataTable table = new DataTable();
public Csharp_ListBox_MySQL()
{
InitializeComponent();
}
private void Csharp_ListBox_MySQL_Load(object sender, EventArgs e)
{
adapter = new MySqlDataAdapter("SELECT * FROM test_db.users",connection);
adapter.Fill(table);
listBoxData.DataSource = table;
listBoxData.DisplayMember = "fname";
listBoxData.ValueMember = "id";
}
}
}
=> OUTPUT :
c# listbox items from mysql database |
Download Projects Source Code