X++直接操作AX数据库
static server void KimCreateProcedure() { LogInProperty m_loginProperty; OdbcConnection m_connection; Statement m_stmt; ResultSet m_sqlres; Str m_strSQL; SqlStatementExecutePermission m_permission; InventTable m_inventTable; SqlSystem sqlSystem = new SqlSystem(); ; select firstonly m_inventTable where m_inventTable.ItemId == "B0000001"; //连接外部数据库 /* m_loginProperty = new LoginProperty(); m_loginProperty.setServer("ERPTEST"); m_loginProperty.setDatabase("ProcedureTest"); */ //连接AX数据库 m_loginProperty = sqlSystem.createLoginProperty(); m_connection = new OdbcConnection(m_loginProperty); m_stmt = m_connection.createStatement(); //直接通过sql语句 m_strSQL = "select * from InventTable where itemId = 'B0000001'"; //调用存储过程 //m_strSQL = "exec Sp_InsertOneItem '" +m_inventTable.ItemId + "','" +m_inventTable.ItemName + "'"; m_permission = new SqlStatementExecutePermission(m_strSQL); m_permission.assert(); m_sqlres = m_stmt.executeQuery(m_strSQL); CodeAccessPermission::revertAssert(); while (m_sqlres.next()) { info(strfmt("itemid %1,itemname: %2",m_sqlres.getString(1),m_sqlres.getString(2))); } }