Hi,
I'm trying to keep my data access code separate from the code behind my form. What I am trying to do is populate my combo-box with a list of CompanyNames here's how I'm trying to bind this combo-box to my Companies entity to retrieve the CompanyName:
C Code:
private void frmMain_Load(object sender, EventArgs e) { dal = new DataAccessLayer(); cmbCompanyNameSearch.DataSource = dal.GetcmbCompanyList(); }
and here's the method in my DataAccessLayer:
This is giving me the following error:C Code:
public List<Companies> GetcmbCompanyList() { // Check we have an ObjectContext if (entities == null) entities = new CompanySecretaryEntities(); // Create a query from the entityset ObjectQuery<Companies> companies = entities.Companies; companies.MergeOption = MergeOption.AppendOnly; // Define the query var query = from c in entities.Companies select c.CompanyName; // Execute the query List<Companies> results = query.ToList(); // Return the results in a List return results; }
Error 1 Cannot implicitly convert type 'System.Collections.Generic.List<string>' to 'System.Collections.Generic.List<CompanySecretary.Companies>'




Reply With Quote