Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7665235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:30:43+00:00 2026-05-31T14:30:43+00:00

I have been working with simple linq2sql statements for a bit but am new

  • 0

I have been working with simple linq2sql statements for a bit but am new to using them with classes. I just want to put the linq statement in the review class and call it from the frmMain class to fill my combobox. I know it should use some properties and the code below is very wrong but any help would be appreciated. Thanks

public partial class frmMain : Form
{
    Review r = new Review();
    r.getEmp();
    cboEmployee.DataSource = emps
}

class Review : frmMain
{
    private "return type?" getEmp()
    {
        using (DataClasses1DataContext db = new DataClasses1DataContext())
        {
            var emps = (from emp in db.employees
                        where emp.active == true
                        orderby emp.name
                        select emp.name.Substring(0, 20)).ToList();
            return emps;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:30:44+00:00Added an answer on May 31, 2026 at 2:30 pm

    In this case, the return type should be List<string> or one of the interfaces it implements.

    You also need to assign the return value to something in the calling code:

    Review r = new Review(); 
    var newDataSource = r.getEmp(); 
    cboEmployee.DataSource = newDataSource;
    

    or simply

    Review r = new Review(); 
    cboEmployee.DataSource = r.getEmp();
    

    In general, the return type of the method must be the type of the value returned from the method, or a supertype of that value. You are returning the result of the ToList() call, so the return type of your method must be compatible with that.

    In your calling code, you seem to be confused by variable scope. The emps variable is a local variable of the getEmp method; it is not visible outside that method.

    Because getEmp is defined in a class other than the one from which it is called, it must be internal or public so it will be visible to the calling class. Or, just define the getEmp method in the frmMain class rather than the Review class. Do you even need a Review class in the first place?

    The first snippet above assigns the return value to another local variable (which I’ve called newDataSource to reduce the potential for confusion), and then assigns the value of that variable to cboEmployee.DataSource. The second sample skips the intermediate assignment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Objective-C and I have been working with simple programs, and I
I just started learning Backbone.js, and have been working on (what else) a simple
I'm rather new to C and have recently been working on making a simple
I have been working to automate some deployment processes using just Nant for the
I'm new to C++ programming, but have been working in C and Java for
I am new to Silverlight and have been working with Simple MVVM to create
I have been working for several of hours on an simple animation but nothing
I have recently been working with Python using Komodo Edit and other simpler editors
I have been working with Visual Studio (WinForm and ASP.NET applications using mostly C#)
I have been working with relational databases for sometime, but it only recently occurred

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.