The name ' ' does not exist in the current context - InfoPath Dev
in

InfoPath Dev

The name ' ' does not exist in the current context

Last post 06-04-2007 09:35 AM by Greg Collins. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 05-30-2007 09:32 AM

    The name ' ' does not exist in the current context

    I am having the above problem in my code. I have searched the forum and have read the different ways of getting this to go away with no success. I am extremely new to infopath and .net. I am familiar with VB but not C#, unfortuanelty most examples are in C# so im trying to learn. Any help would be much appreciated. Thanks.

    public void CTRL60_4_Clicked(object sender, ClickedEventArgs e)

    {

    // get the value of the DOM node that we’ll use to append to the WHERE clause

    currentElementID = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:queryFields/q:_08-Estimate_tbl/@Cost_Center").text;

    // get the value of the DOM node that we’ll use to append to the WHERE clause

    currentElementID = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:queryFields/q:_08-Estimate_tbl/@Cost_Center").text;

    // get the data adapter object

    myDataAdapter = XDocument.DataAdapters("Actuals");

    // set the SQL command property of the data adapter, providing a dynamic WHERE clause

    // set the SQL command property of the data adapter, providing a dynamic WHERE clause

    myDataAdapter.Command = "SELECT DISTINCTROW Job Number as Job_Number, Cost Center as Cost_Center, Year, Month-Year, Sum(Actual Labor Costs) AS Sum_Of_Actual_Labor_Costs, Sum(Actual Non-Labor Costs) AS Sum_Of_Actual_Non-Labor_Costs, Sum(Total Actual Costs) AS Sum_Of_Total_Actual_Costs FROM actuals GROUP BY Job Number, Cost Center, Year, Month-Year";

     // execute the query

    myDataAdapter.Query();

    }

    myDataAdapter.Query();

    }

     // execute the query

    myDataAdapter.Query();

    }

    Errors are:

     Error 1 The name 'currentElementID' does not exist in the current context \My Documents\InfoPath Projects\SO Admin v91\FormCode.cs 38 13 SO Admin v9
    Error 2 The name 'XDocument' does not exist in the current context \My Documents\InfoPath Projects\SO Admin v91\FormCode.cs 38 32 SO Admin v9
    Error 3 The name 'myDataAdapter' does not exist in the current context \My Documents\InfoPath Projects\SO Admin v91\FormCode.cs 41 13 SO Admin v9
    Error 4 The name 'XDocument' does not exist in the current context \My Documents\InfoPath Projects\SO Admin v91\FormCode.cs 41 29 SO Admin v9
    Error 5 The name 'myDataAdapter' does not exist in the current context \My Documents\InfoPath Projects\SO Admin v91\FormCode.cs 45 13 SO Admin v9
    Error 6 The name 'myDataAdapter' does not exist in the current context \My Documents\InfoPath Projects\SO Admin v91\FormCode.cs 48 13 SO Admin v9

  • 05-30-2007 09:37 AM In reply to

    Re: The name ' ' does not exist in the current context

    Sorry for doubling up some of the code. I tried editing it and it keeps posting some stuff twice.
  • 05-30-2007 09:41 AM In reply to

    Re: The name ' ' does not exist in the current context

    You are stuck with different object models. You are currently working in the InfoPath 2007 OM (as identified by the fact that you have a "_Clicked" function and not an "_OnClick" function. Yet you are trying to use the InfoPath 2003 OM to write your code. This won't work.

    You will either need to change your form to use the InfoPath 2003 OM and then use the coding style you are familiar with, or learn how to use the new InfoPath 2007 OM to code.

    For Error 1, did you define currentElementID as a string anywhere? It doesn't look like it in your code sample above. The same question in regards to all the other variables you are using.

  • 05-30-2007 09:48 AM In reply to

    Re: The name ' ' does not exist in the current context

    Greg, Thanks for the fast reply.

    You are right about the OM i am trying to cut and paste from various examples i have found on sites to get the code to work as it is new to me. Can you recommend a could reference site for the new 07 OM? Other than using the help file.

     

     I suppose i dont define either currentElementID or myDataAdapter anywhere in the form. I actually am unsure where. In VB i would simply use something such as:

    DIM currentElementID as integer, myDataAdapter as text

    can i define the same way here?

  • 06-04-2007 09:35 AM In reply to

    Re: The name ' ' does not exist in the current context

    You should be able to change out your code to use VB.NET instead of C# if you are more comfortable with that. I don't have the exact steps, but they shouldn't be too hard to find.

    For the IP07 OM, the MSDN site is the first place I'd go... http://www.msdn.com. I don't know of any others at this time.

    If you stick with C#, you define your variables in a similar way to VB:

    int currentElementID;
    string myDataAdapter;

Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.