AX和数据库直接交互写法
1. 该方法写法比较简单,但是感觉局限性很强
connection con=new connection();
statement stm=con.createStatement();
ResultSET R;
str 1024 strSql;
;
strSql='select top 10 * from inventTable ';
R=stm.executeQuery(strSQL);
while(r.next())
{
print r.getString(1);
}
调用存储过程:
strsql='Execute SP \''+A+'\',\''+B+'\',\''+C+'\''+',\''+D+'\'';//A,B,C,D为动态传过去额参数;
stm.executeUpdate(strsql);//执行,注意函数和执行select的不一样。
2 写法复杂,功能强大
static void ADOTestJob(Args _args)
{
CCADOConnection ccConnection;
CCADOCommand ccCommand;
CCADORecordSet ccRecordset;
CCADOFields ccFields;
str st;
str data1;
int data2;
;
ccConnection = new CCADOConnection();
// Setting the connection string
try
{
ccConnection.connectionString(StrFmt('Provider=SQLOLEDB.1;Persist Security Info=False;User ID=%3;Password=%4;Initial Catalog=%2;Data Source=%1'
, 'dbname' // Server's IP or name
, 'database' // Database or catalog
, 'username' // Username
, 'password' // Password
));
// Open the connection
ccConnection.open();
// Preparing the query
st = "SELECT * FROM salestable";
// Recordset object creation
ccRecordset = new CCADORecordSet();
// Executing the query
ccRecordset.open( st, ccConnection );
// Reading data
while (!ccRecordset.EOF())
{
ccFields = ccRecordset.fields();
// We can access fields either by name or by Index
data1 = ccFields.itemName("salsid").value();
data2 = ccFields.itemIdx(1).value();
info(strfmt("Data %1, %2", data1, data2));
// Read next record
ccRecordset.moveNext();
}
// Closing the connection
ccRecordset.close();
}
catch
{
ccConnection.close();
}
// ccConnection.close();
}
浙公网安备 33010602011771号