Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to get the Data from the Resultset

(0) ShareShare
ReportReport
Posted on by 420

Hi,

I Have to get the Data from the Resultset whatever i have entered in the String edit control. I want only what i entered in the string edit . For example : If i am entering "select accountnum from custtable where name = John. It should return only Accountnum . How to achieve this.  

Sqlquery.PNG

Thanks,

Ram.

Categories:
  • Verified answer
    Martin Dráb Profile Picture
    225,155 Moderator on at
    RE: How to get the Data from the Resultset

    Unfortunately you've merely repeated to what you said before and you didn't address anything from my reply, therefore I have nothing new to say.

    I suggest you start by explaining the business problem that you believe you can solve by your technical design. Then please read my previous reply again and think about what I said there, especially about security and the risk of destroying the database through stored procedures.

  • Verified answer
    nmaenpaa Profile Picture
    101,146 on at
    RE: How to get the Data from the Resultset

    Yes, it's technically possible. It's not recommended for many reasons.

    Also it's possible that Microsoft prevents you from shipping customizations where direct SQL queries are used.

    There's a new tool called AppChecker, which is still in preview. This tool checks for many things and one thing is looking for direct SQL statements in your code. In the future it might be that MS will prevent you from using code that violates the AppChecker rules.

    So I would not invest in a solution that includes direct SQL queries in x++ code.

    General info about AppChecker: ariste.info/.../

    Here's the rule that checks for direct SQL: github.com/.../DirectSQL.xq

  • Karthikeyanbalakrishnan Profile Picture
    420 on at
    RE: How to get the Data from the Resultset

    Hi Martin,

    Users will enter the sql query and the result should be displayed in another string edit control the queries doesn't contain update , insert and delete keywords if it contains this keywords it will popup error. I just want to display the result from the queries. Is that possible to do this.

    Thanks,

    Ram.

  • Verified answer
    Martin Dráb Profile Picture
    225,155 Moderator on at
    RE: How to get the Data from the Resultset

    This is extremely dangerous. For example, you'd allow users to completely bypass security setup and fetch any sensitive data they want. The users must also understand details of AX data model, otherwise they'll do mistakes like forgetting DataAreaId (as you did too above),  struggling to query date-effective data and tables with inheritance, having to deal with surrogate keys and so on. You also don't prevent execution of stored procedures, for example, which allow many things you really don't want people to execute.

    What business problem are you trying to solve by this technical design?

  • Karthikeyanbalakrishnan Profile Picture
    420 on at
    RE: How to get the Data from the Resultset

    Hi Nikolaos,

    I had done the validation on entering the query if the query contains words like Delete , update ,insert it will popup error message invalid query , If i am entering select paytermid from custtable where accountnum=00000001, this should return only that paytermid , to get that paytermid from resultset i will use resultset.getstring(),method . inside the getstring method i will give the table's column position . if i am using real field i have to change my code to resultset.getreal() method . The user may enter any queries except update , delete and insert. The return value from the resultset should be shown in info().

    Thanks,

    Ram

  • Verified answer
    nmaenpaa Profile Picture
    101,146 on at
    RE: How to get the Data from the Resultset

    One more thing, using direct SQL from x++ might not be supported and might not work in the future.

  • Verified answer
    nmaenpaa Profile Picture
    101,146 on at
    RE: How to get the Data from the Resultset

    You should really consider if you want to create a form where users can inject direct SQL statements. Any user of this form might cause data loss and data corruption. I recommend using the table browser to view data from the tables. That comes out of the box for free.

    Anyway, back to your question, if you really want to pursue this path you have to develop some logic that extracts the colum name(s) from the statement, and uses those names to show only the same columns in the result(s). Anything between "select" and "from" are column names, so you can start by trying to extract that info.

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

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Jahanvi Profile Picture

Jahanvi 34

#2
PJ JohnPaul Profile Picture

PJ JohnPaul 5

#3
SudhanshuMSID Profile Picture

SudhanshuMSID 1

Overall leaderboard

Product updates

Dynamics 365 release plans