Home > DeveloperSection > Forums > How to retrieve certain data from Access Database and display them in a combobox
Goti Bandu

Total Post:119

Points:835
Posted on    December-12-2013 1:34 AM

 C# C# 
Ratings:


 1 Reply(s)
 830  View(s)
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.


Pravesh Singh

Total Post:411

Points:2881
Posted on    December-12-2013 2:15 AM

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";

}


Don't want to miss updates? Please click the below button!

Follow MindStick