Axapta ax;
AxaptaRecord custtable;
AxaptaObject query;
AxaptaObject queryrun;
AxaptaObject querybuilddatasource;
AxaptaObject querybuildrange;
//---------------------------------
// 登陸
ax =
new
Axapta();
ax.Logon(
""
,
""
,
""
,
""
);
//---------------------------------
//---------------------------------
// 建立query對象和數據源
query = ax.CreateAxaptaObject(
"Query"
);
querybuilddatasource = query.Call(
"AddDataSource"
, 77)
as
AxaptaObject;
// CustTable的 tableId = 77
querybuildrange = querybuilddatasource.Call(
"AddRange"
, 1)
as
AxaptaObject;
// AccountNum的 fieldId = 1
querybuildrange.Call(
"value"
,
"4000"
);
//查找 AccountNum=4000
//---------------------------------
//---------------------------------
// 執行query
queryrun = ax.CreateAxaptaObject(
"QueryRun"
, query)
as
AxaptaObject;
queryrun.Call(
"prompt"
);
queryrun.Call(
"next"
);
//---------------------------------
//---------------------------------
// 獲取結果
custtable = queryrun.Call(
"getNo"
, 1)
as
AxaptaRecord;
MessageBox.Show((
string
)custtable.get_Field(
"Name"
));
//---------------------------------
//---------------------------------
//註銷
ax.Logoff();
//---------------------------------
|
須要添加引用 Microsoft.Dynamics.BusinessConnectorNet 簡單的:web
Axapta ax;
AxaptaRecord custtable;
AxaptaObject connTest;
//---------------------------------
// 登陸
ax =
new
Axapta();
ax.Logon(
""
,
""
,
""
,
""
);
//---------------------------------
//---------------------------------
// 建立一個ax類對象的實例
connTest = ax.CreateAxaptaObject(
"ConnTest"
);
// 執行方法 getCust
custtable = connTest.Call(
"getCust"
,
"4000"
)
as
AxaptaRecord;
MessageBox.Show((
string
)custtable.get_Field(
"Name"
));
//---------------------------------
//---------------------------------
// 註銷
ax.Logoff();
//---------------------------------
|
ax中代碼:ui
class
ConnTest
{
}
public
CustTable getCust(str _custAccount)
{
Query q;
QueryRun qr;
QueryBuildDataSource qbds;
QueryBuildRange qrange;
TableId _tableId;
CustTable _custtable;
;
_tableId = tablename2id(
"CustTable"
);
q =
new
Query();
qbds = q.addDataSource(_tableId);
qrange = qbds.addRange(fieldname2id(_tableId,
"AccountNum"
));
qrange.value(_custAccount);
qr =
new
QueryRun(q);
qr.interactive(
false
);
qr.prompt();
if
(qr.next())
_custtable = qr.getNo(1);
return
_custtable;
}
|