none
Declare Variable as private (local to form) RRS feed

  • Question

  • HI,

    I am using linq query like below, How do I make variable Sample to scope private?

    Right now I have this code in Form_load event and I want to access 'Sample' in other events of the same form.

     

            Dim Sample = From one In AllOnes _

                    Where one.Value Is Nothing _

                    Select one

    Wednesday, April 7, 2010 8:11 PM

Answers

  • You will need to define what sample is and then place it on a member variable of the form.

    William Wegerson (www.OmegaCoder.Com)
    Wednesday, April 7, 2010 9:09 PM
    Moderator
  • Hello,

    I agree with OmegaMan. You need to define a private member variable outside of Form_Load event and you could access it in other events. For example:
    =======================================
    private DataModels.SchoolEntities schoolDB = null;

    private void Form_Load(object sender, EventArgs e)
    {
             schoolDB = new DataModels.SchoolEntities();
             //.....
    }

    private void button1_Click (object sender, EventArgs e)
    {
            var depts = from d in schoolDB.Department
                              select d;
            //.....
    }
    =======================================

    Best regards


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Tuesday, April 13, 2010 11:05 AM

All replies

  • You will need to define what sample is and then place it on a member variable of the form.

    William Wegerson (www.OmegaCoder.Com)
    Wednesday, April 7, 2010 9:09 PM
    Moderator
  • Hello,

    I agree with OmegaMan. You need to define a private member variable outside of Form_Load event and you could access it in other events. For example:
    =======================================
    private DataModels.SchoolEntities schoolDB = null;

    private void Form_Load(object sender, EventArgs e)
    {
             schoolDB = new DataModels.SchoolEntities();
             //.....
    }

    private void button1_Click (object sender, EventArgs e)
    {
            var depts = from d in schoolDB.Department
                              select d;
            //.....
    }
    =======================================

    Best regards


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Tuesday, April 13, 2010 11:05 AM