HOW TO RETRIEVE CERTAIN DATA FROM ACCESS DATABASE AND DISPLAY THEM IN A COMBOBOX

Goti Bandu

Total Post:119

Points:835
Posted by  Goti Bandu
C# 
C#
 1380  View(s)
Ratings:
Rate this:

The current code i am using to try and get this data is

private void LoadDataToCbo()
    {
        string connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=EmployeeInformation.accdb";
       // string query = @"SELECT FirstName from Employees";
        string query =
            @"SELECT EmpID, LastName + ', ' + FirstName + ' (' + EmployeePosition + ')' as Name FROM Employees";
        OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
        DataTable source = new DataTable();
        dAdapter.Fill(source);
        cboSelectEmp.DataSource = source;
        //cboSelectEmp.ValueMember = "FirstName";
        //cboSelectEmp.DisplayMember = "FirstName";
        cboSelectEmp.DisplayMember = "Name";
        cboSelectEmp.ValueMember = "EmpID";
    }
Any help will be appreciated.
  1. Pravesh Singh

    Post:412

    Points:2888
    Re: How to retrieve certain data from Access Database and display them in a combobox

    Hi Goti,

    private void LoadDataToCbo()
    {
            string connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=EmployeeInformation.accdb";
           // string query = @"SELECT FirstName from Employees";
            string query =           @"SELECT EmpID, LastName & ', ' + FirstName & ' (' & EmployeePosition & ')' as Name FROM Employees";
            OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
            DataTable source = new DataTable();
            dAdapter.Fill(source);
            cboSelectEmp.DataSource = source;
            //cboSelectEmp.ValueMember = "FirstName";
            //cboSelectEmp.DisplayMember = "FirstName";
            cboSelectEmp.DisplayMember = "Name";
            cboSelectEmp.ValueMember = "EmpID";
    }

      Modified On Apr-03-2018 06:24:48 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!