Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

query error CS0103: The name 'query' does not exist in the current context x++

Posted on by 149

Hi,

I'm trying to run a batch job; But while debugging I'm getting an error in the very first while select statement which is as follows "query error CS0103: The name 'query' does not exist in the current context x++" .

Please help me out.

Thankyou!!!! 

  • Apratim Profile Picture
    Apratim 149 on at
    RE: query error CS0103: The name 'query' does not exist in the current context x++

    Hi Martin,

    Thankyou for the reply. I think I might know the issue; will let you know if its solved.

    Thanks again!!

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    RE: query error CS0103: The name 'query' does not exist in the current context x++

    The errors aren't about any problem in your code.

    They mean that you've added query and qr variables to the Watch window and there are no such variables in your current code, therefore the debugger can't show you their values.

  • Apratim Profile Picture
    Apratim 149 on at
    RE: query error CS0103: The name 'query' does not exist in the current context x++

    public static void main(Args _args)
        {
           //declrations of all required tables, classes and EDTs.
           while select * from customtable where
                customtable.Flag == 0
                {
                    //myLogic
                }
        }

    Hi Martin,

    Thankyou for the information you provided.

    Sorry for posting the wrong code I have posted the correct one now. As per your concerns I have declared all the required classes, table and the EDIs that I'm using. including the table in my while select statement.

    Also, I have used Public static void main() in the code.

    Thanks!!

  • Apratim Profile Picture
    Apratim 149 on at
    RE: query error CS0103: The name 'query' does not exist in the current context x++

    touploadto.jpg

    Hi GirishS,

    As per your suggestion I have tried the same logic in a runnable class. Still getting the same error. I have attached a screenshot of the error.

    Thanks!

  • Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    RE: query error CS0103: The name 'query' does not exist in the current context x++

    Moved from Dynamics AX Forum to Dynamics 365 Finance Forum.

    Apratim, please use Insert > Code (in the rich-formatting view) to paste source code. It'll prevent the extra line spacing (caused by the fact that you have each line of code in its own paragraph), it adds line numbering and so on. For example:

    void main (Args _args)
    {
    	while select * from customTable
    		where customTable.field1 == 0  
       {
    		// my logic
       }
    }

    Is it complete code? If so, please compile it - it'll fail because you've never declared custTable variable. If it's not your actual code, please give us the actual code for review.

    I also see an bug there - main() should be static. It again suggests that you gave us something else than what you actual run.

  • GirishS Profile Picture
    GirishS 27,832 Super User 2024 Season 1 on at
    RE: query error CS0103: The name 'query' does not exist in the current context x++

    Hi Apratim,

    Have you tried the same logic in runnable class?

    Create one new runnable class - Add the while select statement into runnable class and see the same error is throwing or not.

    Thanks,

    Girish S.

  • Apratim Profile Picture
    Apratim 149 on at
    RE: query error CS0103: The name 'query' does not exist in the current context x++

    Hi Martin,

    The error is triggering every time I run the batch job (via URL or when triggered  via other methods).

    The code snippet is below:

    void main (Args _args)

    {

    //declrations

    while select * from customTable

        where customTable.field1 == 0  

       {

            // my logic

       }

    }

    The error mentioned in the post is triggering at while select statement.

    I'm working in D365FO PU 50 using VS 2019.

  • Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    RE: query error CS0103: The name 'query' does not exist in the current context x++

    Please show us what code you have at that line. Does it happen if you don't run it in a batch?

    Also, which version of AX is it about?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans