使用VC在ADO中访问存储过程的方法
2007-10-12 12:54
459 查看
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void CADORecordset::AddNewFileNode(CString ShowName , char * ReallyName,long &Id,int root)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_CommandPtr pIDCommand;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pIDCommand.CreateInstance(__uuidof(Command));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pIDCommand->ActiveConnection = m_pConnection;//连接字符串
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pIDCommand->CommandText = "pr_AddNew";//存储过程名
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pIDCommand->CommandType = adCmdStoredProc;//标记该操作为存储过程
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_ParameterPtr m_pParam;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
m_pParam = pIDCommand->CreateParameter("@reid",adInteger,adParamInputOutput,sizeof(int),0);//添加参数该参数为一个inputoutput类型的int参数
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pIDCommand->Parameters->Append(m_pParam);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
m_pParam = pIDCommand->CreateParameter("@ReallyName",adVarChar,adParamInputOutput,128,ReallyName); //添加参数该参数为一个inputoutput类型的VarChar(128)参数
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pIDCommand->Parameters->Append(m_pParam);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
m_pParam = pIDCommand->CreateParameter("@nodeid",adInteger,adParamInput,sizeof(int),root);// 该参数为input类型的int参数,参数的值在root中
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pIDCommand->Parameters->Append(m_pParam);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
m_pParam = pIDCommand->CreateParameter("@ShowName",adChar,adParamInput,ShowName.GetLength(),ShowName.GetBuffer(0)); //数为input类型的char,参数的值在,ShowName.GetBuffer(0)中,该用法要回收
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ShowName.ReleaseBuffer();//回收
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pIDCommand->Parameters->Append(m_pParam);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pIDCommand->Execute(NULL,NULL,adCmdStoredProc);//执行存储过程
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Id = pIDCommand->Parameters->GetItem((long)0)->Value;//根据参数在参数表中的位置取值,当前参数是第一个,所以值为0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CString _reallyname= pIDCommand->Parameters->GetItem((long)1)->Value;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pIDCommand.Detach();//使用完毕后释放资源
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sprintf(ReallyName,_reallyname.Trim().GetBuffer(0));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_reallyname.ReleaseBuffer();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
……
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return ;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
相关文章推荐
- [转]VC中使用ADO调用存储过程实现方法
- VC++中使用ADO访问Oracle遇到的问题及解决方法(待续)
- VC中使用ADO访问数据库技术程序实现方法
- VC中使用ADO访问数据库技术程序实现方法
- VC中使用ADO调用存储过程实现方法
- VC++ MFC SQL ADO数据库访问技术使用的基本步骤及方法
- [转]VC中使用ADO调用存储过程实现方法
- VC++ MFC SQL ADO数据库访问技术使用的基本步骤及方法
- VC中使用ADO调用存储过程实现方法
- VC++ MFC SQL ADO数据库访问技术使用的基本步骤及方法
- VC中使用ADO访问数据库技术程序实现方法
- Sybase ASE数据库使用ADO.net访问存储过程方法详解
- Sybase ASE数据库使用ADO.net访问存储过程方法详解
- MS2010 VC++使用ADO访问数据库
- VB中使用ADO的方法创建及访问Excel文件(原创)
- 使用 ADO.NET 访问 Oracle 9i 存储过程(转)
- VC++使用ADO方法读写Microsoft Access本地数据库文件(不用ODBC)
- VC中使用ADO之二--调用存储过程
- VC中使用ADO操作数据库的方法
- VC++中使用ADO访问SQL Server数据库与Access数据库的不同之处总结