none
the name does not exist in the current context RRS feed

  • Question

  • I am getting error the name 'iayear' doe not exit in the current context. The variables I have defined in the main form as static variables.

    From the main form I am calling this form and the code in the called form is as follows.

    namespace Studinform
    {
        public partial class attdtl : Form
        {
            private fsecEntities fsecContext;
            public attdtl()
            {
                InitializeComponent();
            }
    
            private void attdtl_Load(object sender, EventArgs e)
            {
                fsecContext = new fsecEntities();
        
                
                ObjectParameter mmyear = new ObjectParameter("ayear", @iayear);
                ObjectParameter mmfsecno = new ObjectParameter("afsecno", @ifsecno);
                ObjectParameter mayear = new ObjectParameter("acid", @icid);
                fsecContext.Insertintommodulestudattdtl(@iayear, @ifsecno, @icid);
    
                var studattdtlquery = from s in fsecContext.mmodulestudattdtls
                                      where s.ayear == iyear && s.cid == icourseid && s.fsecno == ifsecno
                                      orderby s.moduleid
                                      select s;
    
    
    
                studattdtlGridView.DataSource = studattdtlquery;
    
    
            }
        }
    }
    
    


    In the main form I have defined the static variables

    namespace

     

    Studinform

    {

     

    public partial class studinfo :

    Form

    {

     

    static int

    iyear = 0;

     

    static int

    icourseid = 0;

     

    static int

    iayear = 0;

     

    static string ifsecno = ""

    ;

     

    static int

    icid = 0;

     

    static int

    z = 0;

     

    static int

    irepeat = 0;

     

    static string imoduleid = ""

    ;

     

    static string ixmoduleid = ""

    ;

     

    static decimal icwmarksobtain

    ----

    ----

    On button press click I am calling another form and in that form I am getting the error.

     

     
    Thursday, January 19, 2012 1:49 PM

Answers

  •  

    Make the following declaration :

    static int iyear = 0;

    to public so that it can be accessed outside of the class, like this : 

    public static int iyear = 0;


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by yesganesh Thursday, January 19, 2012 5:15 PM
    Thursday, January 19, 2012 5:08 PM

All replies

  • Hi yesganesh;

    You need to identify the class that the static variable is located in. The line of code should be as follows:

    ObjectParameter mmyear = new ObjectParameter("ayear", @studinfo.iayear);

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Thursday, January 19, 2012 3:57 PM
  • Hi Fernando,

    Thanks. But I am getting thism error. studinform.studinfo.iayear is inaccessible dut to its protection level.

    when I type @studinfo.  I am unable to find iayear.

     

     


    • Edited by yesganesh Thursday, January 19, 2012 4:56 PM
    Thursday, January 19, 2012 4:56 PM
  •  

    Make the following declaration :

    static int iyear = 0;

    to public so that it can be accessed outside of the class, like this : 

    public static int iyear = 0;


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by yesganesh Thursday, January 19, 2012 5:15 PM
    Thursday, January 19, 2012 5:08 PM