AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX: За рубежом > DAX in English
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 14.07.2005, 03:53   #1  
gb is offline
gb
Участник
 
42 / 15 (1) ++
Регистрация: 31.03.2005
calling SQL sp from Axapta
I have a store procedure that returns s number of records from an external database/table based on a parameter.
In Axapta I need to call that sp and get its returned value.

Does anybody have an example?
Thanks.
Старый 14.07.2005, 09:35   #2  
sukhanchik is offline
sukhanchik
Administrator
Аватар для sukhanchik
MCBMSS
Злыдни
Лучший по профессии 2015
Лучший по профессии AXAWARD 2013
Лучший по профессии 2011
Лучший по профессии 2009
 
3,273 / 3466 (122) ++++++++++
Регистрация: 13.06.2004
Адрес: Москва
usually, stored procedure returns no value. But Axapta has a class \System Documentation\Classes\UserConnection, which provides access to execute SQL operators. Also Axapta has a class \System Documentation\Classes\Statement, which executes SQL operators (see help on theese classes). In this class exists methods executeQuery() for executing queries, which returns any rows and method executeUpdate() for executing queries, which returns no rows.
Try use theese methods and class \System Documentation\Classes\ResultSet for getting count of your records
Старый 14.07.2005, 09:57   #3  
Ace of Database is offline
Ace of Database
Участник
Аватар для Ace of Database
 
870 / 637 (23) +++++++
Регистрация: 14.10.2004
Example:
PHP код:
static void DD_StoredProcReturnRecordsetTest(Args _args)
{
    
str     serverName      "Server";
    
str     baseName        "Database";
    
str     userId          "UserId";
    
str     userPassword    "Password";
    
CCADOConnection         cn;
    
COM                     comCN;
    
COM                     cmd;
    
CCADORecordset          rs;
    
int                     i;
    ;

    
cn = new CCADOConnection();
    
cn.open(
        
"Provider=SQLOLEDB;"+
        
"Data Source="      serverName    +   ";" +
        
"Initial Catalog="  baseName      +   ";" +
        
"uid="              userId        +   ";" +
        
"pwd="              userPassword);

    
comCN cn.connection();

    
cmd     = new COM("ADODB.Command");
    
cmd.activeConnection(comCN);
    
cmd.commandType(4);  //adCmdStoredProc, see ObjectBrowser in VBA  
    
cmd.CommandText("spTestReturnRecordset");
    
rs = new CCADORecordset(cmd.Execute());
    while (!
rs.eof())
    {
        
info(strfmt("%1"rs.fields().itemIdx(0).value()));
        
rs.movenext();
    }

    
cn.close();

Sooner I was able to pass parameters to stored procedures in Axapta. But now I forget how to do it
За это сообщение автора поблагодарили: Gustav (1).
Старый 14.07.2005, 13:23   #4  
Ace of Database is offline
Ace of Database
Участник
Аватар для Ace of Database
 
870 / 637 (23) +++++++
Регистрация: 14.10.2004
Example: how to pass parameter to stored procedure and get a recordset from it:

PHP код:
static void DD_StoredProcReturnRecordsetTest(Args _args)
{
    
str     serverName      "Server";
    
str     baseName        "Database";
    
str     userId          "UserId";
    
str     userPassword    "Password";
    
CCADOConnection         cn;
    
COM                     comCN;
    
COM                     cmd;
    
COM                     paramparams;
    
COMVariant              emptyParam;
    
COMVariant              result;
    
CCADORecordset          rs;
    
str                     parameter;
    ;

    
cn = new CCADOConnection();
    
cn.open(
        
"Provider=SQLOLEDB;"+
        
"Data Source="      serverName    +   ";" +
        
"Initial Catalog="  baseName      +   ";" +
        
"uid="              userId        +   ";" +
        
"pwd="              userPassword);

    
comCN cn.connection();

    
cmd     = new COM("ADODB.Command");

    
cmd.activeConnection(comCN);
    
cmd.commandType(1);  //adCmdText, see ObjectBrowser in VBA
    
parameter "Parameter value";

    
cmd.CommandText(strfmt("exec spTestReturnRecordset '%1'"parameter));

    
rs = new CCADORecordset(cmd.Execute());
    while (!
rs.eof())
    {
        
info(strfmt("%1"rs.fields().itemIdx(0).value()));
        
rs.movenext();
    }

    
cn.close();

Старый 14.07.2005, 18:56   #5  
gb is offline
gb
Участник
 
42 / 15 (1) ++
Регистрация: 31.03.2005
Well, actually the question was how to catch a returned value from stored procedure. Say, my return procedure returns an integer:
RETURN @return_value

I don't want to loop through the result set, I just want to get that returned value.

The other question, I usually use ODBCConnection, Statement, and ResultSet to accomplish what you showed in your examples.
Is there an advantage to use one approach vs. another?

Thanks for your input.
Good day.
Старый 15.07.2005, 00:33   #6  
sukhanchik is offline
sukhanchik
Administrator
Аватар для sukhanchik
MCBMSS
Злыдни
Лучший по профессии 2015
Лучший по профессии AXAWARD 2013
Лучший по профессии 2011
Лучший по профессии 2009
 
3,273 / 3466 (122) ++++++++++
Регистрация: 13.06.2004
Адрес: Москва
Цитата:
Say, my return procedure returns an integer:
Your procedure cannot return value (Transact-SQL ?).
Function can return value. If you use a function, I recommend to write:
PHP код:
        cmd.commandType(1);  //adCmdText, see ObjectBrowser in VBA
    
parameter "Parameter value";

    
cmd.CommandText(strfmt("SELECT spTestReturnRecordset '%1'"parameter)); 
as wrote Ace of Database, but do replace EXEC on SELECT
Старый 15.07.2005, 00:39   #7  
gb is offline
gb
Участник
 
42 / 15 (1) ++
Регистрация: 31.03.2005
Thank you.
Thank you all.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
axaptabuilder: How to build Axapta application from XPO files stored in Visual Source Safe. Blog bot DAX Blogs 0 12.04.2007 16:10
axaptabuilder: How to build Axapta application from XPO files stored in Visual Source Safe. Blog bot DAX Blogs 0 22.11.2006 15:20
Fred Shen: Convert Axapta date type value to datetime type value in SQL Server Blog bot DAX Blogs 0 28.10.2006 16:40
Говорят вышел SP2 для Axapta 3. Кто нибуть что знает на эту тему? soin DAX: Прочие вопросы 10 13.10.2003 10:43
Введение в Аксапту Роман Кошелев DAX: Прочие вопросы 0 18.12.2001 14:00
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 22:53.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.