AutoFill the data from a particular column from DataBase into a ComboBox

In this article, we will autofill the CustomerNames from CustomerDetails table in a ComboBox on FormLoad event.
Create a CobmoBox say cmbCustomerName on your form.

Write the following code in the FormLoad event of your code.
Use the code for getCustomerDetails() function from https://tutorials4sharepoint.wordpress.com/2017/11/08/get-all-the-data-from-a-table-in-ms-access-database-using-c-ado-net/ post.

DataTable custDt = new DataTable();
custDt = getCustomerDetails();
cmbCustomerName.DataSource = custDt;
if(custDt!=null)
{
     cmbCustomerName.BindingContext = this.BindingContext;
     cmbCustomerName.DisplayMember = "CustomerName";
     cmbCustomerName.ValueMember = "CustomerID";
     cmbCustomerName.Text = "-Select Option-";
}
else
     cmbCustomerName.Text = "No Customer Data Available!";
Power Platform Academy

Start or Upgrade your Career with Power Platform

Learn with Akanksha

Python | Azure | AI/ML | OpenAI | MLOps

Design a site like this with WordPress.com
Get started