#import "c:\program files\common files\system\ado\msado15.dll" rename ("EOF","adoEOF") no_namespace
..._ConnectionPtr m_pConnection; //数据库连接对象
_CommandPtr m_pCommand;      //命令集
_RecordsetPtr m_pRecordset;  //结果集_ParameterPtr spPAR1;          //参数1
        _ParameterPtr spPAR2          //参数2
_ParameterPtr spPAR3;          //参数3
_ParameterPtr spPAR4;          //参数4
        
        m_pConnection.CreateInstance("ADODB.Connection"); 
        m_pCommand.CreateInstance("ADODB.Command");
        m_pRecordset.CreateInstance("ADODB.Recordset");         CREATEiNSTANCE(spPAR1,Parameter) ;    //参数1
        CREATEiNSTANCE(spPAR2,Parameter) ;    //参数2
        CREATEiNSTANCE(spPAR3,Parameter) ;    //参数3
        CREATEiNSTANCE(spPAR4,Parameter) ;    //参数4        hrCon=m_pConnection->Open("","","",-1);  //连接字符串偶就不写了
        m_pCommand->ActiveConnection=m_pConnection;
        m_pRecordset->PutRefActiveConnection(m_pConnection); 
        
        m_pCommand->CommandType=adCmdStoredProc;//说明命令类型--存储过程        spPAR1=m_pCommand->CreateParameter("存储过程参数1",      adVarChar,adParamInput,8); //指定参数类型,长度
        m_pCommand->Parameters->Append(spPAR1); spPAR2=m_pCommand->CreateParameter("存储过程参数2",      
adVarChar,adParamInput,8); //指定参数类型,长度
        m_pCommand->Parameters->Append(spPAR2); spPAR3=m_pCommand->CreateParameter("存储过程参数1",      adVarChar,adParamInput,8); //指定参数类型,长度
        db->m_pCommand->Parameters->Append(spPAR3); spPAR4=m_pCommand->CreateParameter("存储过程参数1",      adVarChar,adParamInput,8); //指定参数类型,长度
        m_pCommand->Parameters->Append(spPAR4); spPAR4=...;
spPAR4=...;
spPAR4=...;
spPAR4=...;  //参数赋值

解决方案 »

  1.   

    #import "c:\program files\common files\system\ado\msado15.dll" rename ("EOF","adoEOF") no_namespace
    ..._ConnectionPtr m_pConnection; //数据库连接对象
    _CommandPtr m_pCommand;      //命令集
    _RecordsetPtr m_pRecordset;  //结果集_ParameterPtr spPAR1;          //参数1
            _ParameterPtr spPAR2          //参数2
    _ParameterPtr spPAR3;          //参数3
    _ParameterPtr spPAR4;          //参数4
            
            m_pConnection.CreateInstance("ADODB.Connection"); 
            m_pCommand.CreateInstance("ADODB.Command");
            m_pRecordset.CreateInstance("ADODB.Recordset");         CREATEiNSTANCE(spPAR1,Parameter) ;    //参数1
            CREATEiNSTANCE(spPAR2,Parameter) ;    //参数2
            CREATEiNSTANCE(spPAR3,Parameter) ;    //参数3
            CREATEiNSTANCE(spPAR4,Parameter) ;    //参数4        hrCon=m_pConnection->Open("","","",-1);  //连接字符串偶就不写了
            m_pCommand->ActiveConnection=m_pConnection;
            m_pRecordset->PutRefActiveConnection(m_pConnection); 
            
            m_pCommand->CommandType=adCmdStoredProc;//说明命令类型--存储过程        spPAR1=m_pCommand->CreateParameter("存储过程参数1",      adVarChar,adParamInput,8); //指定参数类型,长度
            m_pCommand->Parameters->Append(spPAR1); spPAR2=m_pCommand->CreateParameter("存储过程参数2",      
    adVarChar,adParamInput,8); //指定参数类型,长度
            m_pCommand->Parameters->Append(spPAR2); spPAR3=m_pCommand->CreateParameter("存储过程参数1",      adVarChar,adParamInput,8); //指定参数类型,长度
            db->m_pCommand->Parameters->Append(spPAR3); spPAR4=m_pCommand->CreateParameter("存储过程参数1",      adVarChar,adParamInput,8); //指定参数类型,长度
            m_pCommand->Parameters->Append(spPAR4); spPAR4=...;
    spPAR4=...;
    spPAR4=...;
    spPAR4=...;  //参数赋值
      

  2.   

    用dblib执行也很方便,到msdn里查找dbcmd可以得到相关信息,需要连接ntwdblib.lib
      

  3.   

    DBPROCESS    *dbproc;
    LOGINREC    *loginrec; loginrec = dblogin();
    DBSETLUSER(loginrec,"wsq");
    DBSETLPWD(loginrec,"wsq");
    //DBSETLAPP(loginrec, "my_program");
    dbproc = dbopen(loginrec,"mars"); if(dbproc==NULL)
    {
    AfxMessageBox("error dbproc");
    return;
    }
    dbcmd(dbproc,"select * from wt_account");
    dbsqlexec(dbproc);
    dbresults(dbproc); unsigned char account[21];
    memset(account,0,sizeof(account));
    dbbind(dbproc,2,STRINGBIND,(DBINT)0,account); CString str;
    int num=0;
    while (dbnextrow(dbproc) != NO_MORE_ROWS)
    {
    //C-code to print or process row data
    CString tt;
    account[20]=0;
    tt.Format("%-20s",account); ;
    str += tt;
    num++; if(num>=100) 
    {
    str += "\nand more....\n";
    break;
    }
    } dbclose(dbproc); if(str == "")
    str = "There is no account in SQL Server!";
    AfxMessageBox(str);
    //在dbcmd的时候用SQL语句调用存储过程就可以了
      

  4.   

    文件开头需要
    #define DBNTWIN32
    #include "Sqlfront.h"
    #include "Sqldb.h"在NT、2000下连接SQL7.0没问题。
      

  5.   

    dbrpcinit存储过程名
    dbrpcparam绑定参数
    dbrpcsend发送
    dbrpcok等待结果