Using QueryRun datatype in C#

前提是你 提交于 2019-12-13 03:59:14

问题


I was wondering if it is possible to use the QueryRun object in c# and if so, which namespace do I import to use it, as I have a method which returns a QueryRun object in my AX class, which I call in my C# code like so:

CallStaticClassMethod("OnlineUsers", "findMultipleProducts", user, id);

findMultipleProducts is the method in question, I need to access it as a QueryRun object as I need to iterate through the products using the .next() method. Any help or examples would be appreciated.


回答1:


Are you accessing Ax through BC.NET? If so here is a sample of how to use QueryRun from BC.NET:

    using (var ax = new Axapta())
    {
        ax.Logon(null, null, null, null);
        int tableId = ax.GetTableId("TaxTable");
        var query = ax.CreateAxaptaObject("Query");
        var qbd = (AxaptaObject)query.Call("addDataSource", tableId);

        var qr = ax.CreateAxaptaObject("QueryRun", query); 

        while ((bool)qr.Call("next"))
        {
            var record = (AxaptaRecord)qr.Call("Get", tableId); 

            Console.WriteLine("TaxCode: {0}", record.get_Field("TaxCode"));
            Console.WriteLine("TaxName: {0}", record.get_Field("TaxName"));
        }
        ax.Logoff();
    } 

Where the GetTableId extension method is taken from this post:

    public static class AxaptaExtensions
    {
        public static int GetTableId(this Axapta ax, string table)
        {
            return (int)ax.CallStaticClassMethod("Global", "tableName2Id", table);
        }
    }


来源:https://stackoverflow.com/questions/9663759/using-queryrun-datatype-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!