在C#中使用QueryRun数据类型 [英] Using QueryRun datatype in C#
问题描述
我想知道是否可以在c#中使用QueryRun对象,如果可以,我要导入哪个名称空间以使用它,因为我有一个方法可以在我的AX类中返回QueryRun对象,在我的调用中像这样的C#代码:
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是有问题的方法,由于需要使用.next()方法遍历产品,因此我需要将其作为QueryRun对象进行访问.任何帮助或示例,将不胜感激.
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.
推荐答案
您是否通过BC.NET访问Ax?如果是这样,下面是如何从BC.NET使用QueryRun的示例:
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();
}
GetTableId扩展方法取自此帖子:
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);
}
}
这篇关于在C#中使用QueryRun数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!