web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Exporting data from external database (sql) to AX2009

(0) ShareShare
ReportReport
Posted on by

Dear All.I can connect to odbc and fetch the data from external db(which can see in infolog),but how can I insert the data in my staging table in ax. I need help of some coding example on how to import the data to my staging table.

I use code below to connect and get data from external db, but cant insert the data into staging stable.

----------------------

void clicked()

{

   ODBCConnection   myODBC;

   Statement   myStatement;

   LoginProperty   myLP;

   ResultSet   myRs;

   str     mySQLStatement,st2;

   str     myConnStr;

   str     myDSN = "xx";

   str     myUserName = "xxxxxx";

   str     myPassword = "xxxxxxx";

 

   CTG   stagingTbl;

   ;

   myConnStr = strfmt("DSN=%1;UID=%2;PWD=%3", myDSN, myUserName, myPassword);

   myLP = new LoginProperty();

   myLP.setOther(myConnStr);

   try

   {

       myODBC = new ODBCConnection(myLP);

       myStatement = myODBC.createStatement();

 

       mySQLStatement = "Select * from CTG";

       myRs = myStatement.executeQuery(mySQLStatement);//szs

       while(myRs.next())

       {

           info(strfmt("%1 %2 %3 %4", myRs.getString(1), myRs.getString(2), myRs.getString(3), myRs.getString(4)));

           //stagingTbl.clear();//szs

           stagingTbl.createdDate = myRs.getDateTime(1);

           stagingTbl.changedDate = myRs.getDateTime(2);

           stagingTbl.CTG = myRs.getString(3);

           stagingTbl.CTGDescription = myRs.getString(4);

         stagingTbl.insert();

       }

   }

   catch

   {

       error('unexpected error');

   }

   //super();

}

---------------

My staging table is CTG. But the code to insert data into staging table did not work.

Thank You

*This post is locked for comments

I have the same question (0)
  • Anton Venter Profile Picture
    20,678 Super User 2026 Season 1 on at

    Can you please give more information about what happens when you run the code so I don't have to guess.

  • Suggested answer
    Rudi Hansen Profile Picture
    4,079 on at

    Hmm this should work, only real error i can see is that your commented out the line with stagingTbl.clear(); you need to do that so you are sure you are working on a new record.

    Also the stagingTbl.createdDate = myRs.getDateTime(1) and stagingTbl.changedDate = myRs.getDateTime(2) you can remove those lines, those fields are maintained by ax automatically so you can't change them in this way.

    You may also have to add ttsbegin and ttscommit, though they are not really necessary in AX2009 its best praksis to use them.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 16

#2
GiacomoRovai Profile Picture

GiacomoRovai 4

#3
Douglas Noel Profile Picture

Douglas Noel 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans