AX调用存储过程
X++ 通过OdbcConnection访问数据库,调用存储过程。
要注意一点,调用存储过程的窗体或者类方法等,必须要有开发者权限。
static void SpJob(Args _args)
{
LoginProperty m_loginProperty; //登录配置
OdbcConnection m_connection; //链接对象
Statement m_stmt; //状态
ResultSet m_sqlres; //结果集
Str m_strSQL; //查询字符串
SqlStatementExecutePermission m_permission; //执行权限
;
m_loginProperty = new LoginProperty();
m_loginProperty.setServer("Kurodo\\SQL2008");
m_loginProperty.setServer("AX_DEV");
m_connection = new OdbcConnection(m_loginProperty);
m_stmt = m_connection.createStatement();
m_strSQL = strfmt("exec Sp_SelectSp '%1','%2'",11,22); //执行存储过程参数 11 22
m_permission = new SQLStatementExecutePermission(m_strSQL);
m_permission.assert();
m_sqlres = m_stmt.executeQuery(m_strSQL);
CodeAccessPermission::revertAssert();
while(m_sqlres.next())
{
info(strfmt("ID: %1 Name: %2",m_sqlres.getInt(1),m_sqlres.getString(2))); //数据集对应类型
}
pause;
}
{
LoginProperty m_loginProperty; //登录配置
OdbcConnection m_connection; //链接对象
Statement m_stmt; //状态
ResultSet m_sqlres; //结果集
Str m_strSQL; //查询字符串
SqlStatementExecutePermission m_permission; //执行权限
;
m_loginProperty = new LoginProperty();
m_loginProperty.setServer("Kurodo\\SQL2008");
m_loginProperty.setServer("AX_DEV");
m_connection = new OdbcConnection(m_loginProperty);
m_stmt = m_connection.createStatement();
m_strSQL = strfmt("exec Sp_SelectSp '%1','%2'",11,22); //执行存储过程参数 11 22
m_permission = new SQLStatementExecutePermission(m_strSQL);
m_permission.assert();
m_sqlres = m_stmt.executeQuery(m_strSQL);
CodeAccessPermission::revertAssert();
while(m_sqlres.next())
{
info(strfmt("ID: %1 Name: %2",m_sqlres.getInt(1),m_sqlres.getString(2))); //数据集对应类型
}
pause;
}