简单例程例程:
void
CADORecordset::AddNewFileNode(CString ShowName ,
char
*
ReallyName,
long
&
Id,
int
root)
... {
_CommandPtr pIDCommand;
pIDCommand.CreateInstance(__uuidof(Command));
pIDCommand->ActiveConnection = m_pConnection;//连接字符串
pIDCommand->CommandText = "pr_AddNew";//存储过程名
pIDCommand->CommandType = adCmdStoredProc;//标记该操作为存储过程
_ParameterPtr m_pParam;
m_pParam = pIDCommand->CreateParameter("@reid",adInteger,adParamInputOutput,sizeof(int),0);//添加参数该参数为一个inputoutput类型的int参数
pIDCommand->Parameters->Append(m_pParam);
m_pParam = pIDCommand->CreateParameter("@ReallyName",adVarChar,adParamInputOutput,128,ReallyName); //添加参数该参数为一个inputoutput类型的VarChar(128)参数
pIDCommand->Parameters->Append(m_pParam);
m_pParam = pIDCommand->CreateParameter("@nodeid",adInteger,adParamInput,sizeof(int),root);// 该参数为input类型的int参数,参数的值在root中
pIDCommand->Parameters->Append(m_pParam);
m_pParam = pIDCommand->CreateParameter("@ShowName",adChar,adParamInput,ShowName.GetLength(),ShowName.GetBuffer(0)); //数为input类型的char,参数的值在,ShowName.GetBuffer(0)中,该用法要回收
ShowName.ReleaseBuffer();//回收
pIDCommand->Parameters->Append(m_pParam);
pIDCommand->Execute(NULL,NULL,adCmdStoredProc);//执行存储过程
Id = pIDCommand->Parameters->GetItem((long)0)->Value;//根据参数在参数表中的位置取值,当前参数是第一个,所以值为0
CString _reallyname= pIDCommand->Parameters->GetItem((long)1)->Value;
pIDCommand.Detach();//使用完毕后释放资源
sprintf(ReallyName,_reallyname.Trim().GetBuffer(0));
_reallyname.ReleaseBuffer();
……
return ;
}
... {
_CommandPtr pIDCommand;
pIDCommand.CreateInstance(__uuidof(Command));
pIDCommand->ActiveConnection = m_pConnection;//连接字符串
pIDCommand->CommandText = "pr_AddNew";//存储过程名
pIDCommand->CommandType = adCmdStoredProc;//标记该操作为存储过程
_ParameterPtr m_pParam;
m_pParam = pIDCommand->CreateParameter("@reid",adInteger,adParamInputOutput,sizeof(int),0);//添加参数该参数为一个inputoutput类型的int参数
pIDCommand->Parameters->Append(m_pParam);
m_pParam = pIDCommand->CreateParameter("@ReallyName",adVarChar,adParamInputOutput,128,ReallyName); //添加参数该参数为一个inputoutput类型的VarChar(128)参数
pIDCommand->Parameters->Append(m_pParam);
m_pParam = pIDCommand->CreateParameter("@nodeid",adInteger,adParamInput,sizeof(int),root);// 该参数为input类型的int参数,参数的值在root中
pIDCommand->Parameters->Append(m_pParam);
m_pParam = pIDCommand->CreateParameter("@ShowName",adChar,adParamInput,ShowName.GetLength(),ShowName.GetBuffer(0)); //数为input类型的char,参数的值在,ShowName.GetBuffer(0)中,该用法要回收
ShowName.ReleaseBuffer();//回收
pIDCommand->Parameters->Append(m_pParam);
pIDCommand->Execute(NULL,NULL,adCmdStoredProc);//执行存储过程
Id = pIDCommand->Parameters->GetItem((long)0)->Value;//根据参数在参数表中的位置取值,当前参数是第一个,所以值为0
CString _reallyname= pIDCommand->Parameters->GetItem((long)1)->Value;
pIDCommand.Detach();//使用完毕后释放资源
sprintf(ReallyName,_reallyname.Trim().GetBuffer(0));
_reallyname.ReleaseBuffer();
……
return ;
}