当前位置:首页
开发技术指南» 文章正文
    引言:
 

 

    摘要: 还有取datetime类型的应该用哪个,谢谢了 ......
    摘要: 如题! 另外,如何给分啊,每次大哥们给我解决了问题我都不知道怎么给分! ......


vc里调用sqlserver存储过程如何调用

我的代码是这样    
  ::CoInitialize(NULL);          
    _ConnectionPtr   pConn;  
    pConn.CreateInstance(_uuidof(Connection));  
    pConn->Open("Provider   =   LOLEDB.1;  
                              InitialCatalog=aa;  
                              DataSource=201.123.133.123",  
                              "sa","",adOpenUnspecified);  
    pConn->Execute(proc(a,b),0,adCmdUnknown);  
   
  是这样的,a   是输入参数,  
  b是输出参数  
  我这段语法不知道怎么写  
  我想得到b得值  
   
  没有输出参数的情况下是能调用的    
   
 

NO.1   作者: pengdali

below   is   from   MSDN,you   can   find   a   lot   of   technical   article   in   MSDN   if   you   search"stored   procedure   and   VC"  
  good   luck  
   
  Steps   To   Reproduce   Behavior  
  In   the   SQL   Server   7.0   Query   Analyzer   select   the   test   database   Pubs.  
   
   
  Create   the   following   stored   procedure.   This   stored   procedure   returns   a   recordset   and   an   out   parameter   count.  
   
   
   
  if   exists   (select   *   from   sysobjects   where   id   =   object_id(N[dbo].[GetJobs])   and   OBJECTPROPERTY(id,   NIsProcedure)   =   1)  
        drop   proc   GetJobs  
        go  
        create   proc   GetJobs   @id   as   int,   @count   as   int   [out]   as  
        begin  
        Select   @count   =   Count(*)   from   jobs   where   job_id   >@id  
        Select   *   from   jobs   where   job_id   >@id  
        end  
        go  
     
   
   
   
  Use   VC   App   Wizard   to   create   a   new   console   application   and   modify   the   code   as   follows:  
   
   
   
  #include   "stdafx.h"  
        #include   "stdio.h"  
        #import   "C:\PROGRA~1\COMMON~1\System\ado\msado15.dll"   no_namespace   rename   ("EOF",   "EOF2")  
   
        struct   InitOle   {  
            InitOle()     {   ::CoInitialize(NULL);   }  
            ~InitOle()   {   ::CoUninitialize();       }  
        }   _init_InitOle_;  
   
        int   main(int   argc,   char*   argv[])  
        {  
        _variant_t   varErr((long)0,   VT_ERROR);  
        _CommandPtr   comm(__uuidof(Command));  
        _ConnectionPtr   conn(__uuidof(Connection));  
   
        _bstr_t   connstr="Provider=SQLOLEDB.1;Persist   Security   Info=False;User   ID=sa;Initial   Catalog=pubs;Data   Source=(local)";  
        conn->Open(connstr,   "",   "",   adConnectUnspecified);  
        comm->ActiveConnection=conn;  
        comm->CommandText="GetJobs";  
        comm->CommandType   =   adCmdStoredProc   ;    
        comm->Parameters->Refresh();  
        _variant_t   recs;  
   
        comm->Parameters->Item[_variant_t((short)1)]->Value=   _variant_t((long)5);  
        _RecordsetPtr   rs   =   comm->Execute(&recs,   &vtMissing,adCmdStoredProc);    
   
        _variant_t   recordcount=   comm->Parameters->Item[_variant_t((short)2)]->Value;  
   
        printf("recordcount   =   %li\n",   (long)recordcount);  
        return   0;  
        }  
     
   
   
  Change   the   Datasource,   User   ID   and   password   in   the   connection   string   above.  
   
   
   
   
  The   recordcount   variant   that   the   above   code   returns   is   of   type   VT_NULL   rather   than   the   number   of   records   that   the   stored   procedure   returns.  
 

NO.2   作者: zjcxc

如果有输入参数,就要用adodb.command对象来调用才行.  
   
  在VC中的具体写法,请转VC版.

NO.3   作者: hjb111

转入VC版吧!

NO.4   作者: erigido

同意楼上地


 ·weblogic最新版本哪里有。。。    »显示摘要«
    摘要: 请问weblogic最新版本哪里有。。。 ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE