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 377795
In Process

The Archive Base Latest Questions

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

Can someone please explain the below to me. First is how I call the

  • 0

Can someone please explain the below to me. First is how I call the method and the second bit is the LINQ Method.

My curiousity stems from the fact that I get a context error if I un-comment the using portion.

Why? I apparently do not fully understand using and context's. And I would like to better understand this.

Guid workerID = new Guid(new ConnectDAL.DAL.Security().GetUserIDByUserLogin(HUD.CurrentUser));

        var myMembers = BLLCmo.GetAllMembers(workerID);
        if (myMembers.Rows.Count != 0)
        {
            dgvMyMembers.DataSource = myMembers;
        }
        else
        {
            var allMembers = BLLCmo.GetAllMembers();
            dgvMyMembers.DataSource = allMembers;
        }




    internal static CmoDataContext context = new CmoDataContext();

    public static DataTable GetAllMembers()
    {
        DataTable dataTable;

        //using (context)
        //{
            var AllEnrollees = from enrollment in context.tblCMOEnrollments
                               select new
                                       {
                                           enrollment.ADRCReferralID,
                                           enrollment.ClientID,
                                           enrollment.CMONurseID,
                                           enrollment.CMOSocialWorkerID,
                                           enrollment.DisenrollmentDate,
                                           enrollment.DisenrollmentReasonID,
                                           enrollment.EconomicSupportWorkerID,
                                           enrollment.EnrollmentDate
                                       };

            dataTable = AllEnrollees.CopyLinqToDataTable();
        //}
        return dataTable;
    }
  • 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-12T14:43:52+00:00Added an answer on May 12, 2026 at 2:43 pm

    “using” blocks automatically dispose of the object you’re using. Since you didn’t give further details on what the exact error is, I’m betting its related to the fact that the “using” will dispose of your “context”, and then later you’ll try to use your context again.

    Data Contexts should be used atomically. They’re already internally coded to be efficient that way, there’s usually no justifiable reason to have one as long-running as you do. The reason you see most samples that use a “using” is because they have the data context initialized immediately before the using (or in it) and then don’t try to referenced the disposed context.

    As a final note, disposing of objects causes them to release all their internal memory references (such as open connections, cached data, etc).

    //Our context exists right now ... unless we've already called this method since the app started ;)
    var myMembers = BLLCmo.GetAllMembers(workerID); // Context is disposed at the end of this call
    if (myMembers.Rows.Count != 0)
    {
      dgvMyMembers.DataSource = myMembers;  //No prob, we didn't call our function again
    }
    else
    {
      var allMembers = BLLCmo.GetAllMembers();  // Oops, our context was disposed of earlier
      dgvMyMembers.DataSource = allMembers;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please explain why push behaves the way as shown below? Basically I
Can someone please explain re-usable structures for me? I was working on making some
Can someone please give an example of how to use the HashMap forall() method?
When copying and pasting a bit of sample code from MSDN, I came up
First let me explain that I have this script that should let users enter
I was just reading http://api.jquery.com/event.stopPropagation/ Since the .live() method handles events once they have
Description of the problem: Create a 'custom control'. Set it's property AutoScroll to 'true'.
I am going through some exam questions for the 70-536 exam and an actual
I am using MVVM Light toolkit Messenger class- A Messenger class (and diverse message
I'm trying to build a simple echo server/client that works on ethernet level(using raw

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.