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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Supplied Method Arguments Are not Valid error when using business connector

(0) ShareShare
ReportReport
Posted on by 931

Hi All, I am new to Business Connector in AX.

I try to display customer Id and customer Name in Console window. I get the error as Supplied Method Arguments Are not Valid .

I am sharing my code , correct me where i am wrong.

Thanks In Advance,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Dynamics.BusinessConnectorNet;
namespace BCClass_Demo
{
    class Program
    {
        static void Main(string[] args)
        {
            Axapta ax;
            AxaptaRecord axRecord,axRecord1;
            String tableName = "CustTable";
            String tableName1 = "DirPartyTable";      
            String sqlStmt = ("Select * from %2 join %1 where %2.RecId == %1.party");
            Object cusid ,  name;
            try
            {
                ax = new Axapta();
                ax.Logon(null, null, null, null);
                axRecord = ax.CreateAxaptaRecord(tableName);                
                axRecord1 = ax.CreateAxaptaRecord(tableName1);                    
                axRecord.ExecuteStmt(sqlStmt);
                while (axRecord.Found)
                {
                   cusid = axRecord.get_Field("AccountNum");                           
                   name = axRecord1.get_Field("Name");
                   Console.WriteLine("CustAccountNum \t CustomerName" );
                   Console.WriteLine(cusid + "\t\t  " +name);
                   axRecord.Next();
                 }
                 Console.ReadKey();

        } 

       catch (Exception e)// I caught error as Supplied Method Arguments Are not Valid
       {
                Console.WriteLine("error" + e);
        }
     }
 }

}

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Mea_ Profile Picture
    60,284 on at

    Hi Rusty Ryan,

    Please look at ExecuteStmt function description msdn.microsoft.com/.../microsoft.dynamics.businessconnectornet.axapta.executestmt.aspx you should pass record as second parameter as well.

  • ThivaKar Profile Picture
    931 on at

    Hi ievgen,

    Thank you for the heads up.. how silly of me, missed that ...

    Thanks again.. :)

    And another quick question, As i said i am trying to print the customer id and customer name , Is my Relation is Correct? Bcoz when i run i getting infinite while loop and im getting the first customer name only .. Pls Advice

  • ThivaKar Profile Picture
    931 on at

    I have changed the while loop as while(axRecord1.Found) which is now infinite.. and it brings only the first customer name

  • ThivaKar Profile Picture
    931 on at

    False Alarm ievgen, Thanks for your support ,, I changed my SQL stmt to

    "Select * from %1 join %2 where %1.Party== %2.RecId" and my changed my while loop back as while(axRecord.Found)  and it works perfectly.

    But if u give me heads up on why this stmt won't work

    "Select * from %2 join %1 where %2.RecId == %1.party"

    will help me .. Thanks in Advance

  • veera seenivasan Profile Picture
    575 on at

    Hi Rusty,

             Ax record belongs to Custtable. Axrecord1 belongs to Dirpartytable when you are looping in Only Axrecord1 it will not have the table fields of Axrecord .So try to use both

  • ThivaKar Profile Picture
    931 on at

    Yes Absolutely , and as i said changed back to while(axRecord.Found).. inside my loop i have name = axRecord1.get_Field("Name");// This gives me correct customer name bcoz of the sql statement , no need to use both..

    "Select * from %1 join %2 where %1.Party== %2.RecId"

    Right Now i am asking , why this statement won't work ??

    "Select * from %2 join %1 where %2.RecId == %1.party"

  • ThivaKar Profile Picture
    931 on at

    Hi ievgen, Can you tell me the ans for my above question?

  • Mea_ Profile Picture
    60,284 on at

    Hi Rusty Ryan,

    Can you post full method's code to see how are you using this statement.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans