VC执行存储过程
来源:互联网 发布:域名注册什么好 编辑:程序博客网 时间:2024/05/22 02:02
VC执行存储过程
1.VC执行一个带参数的存储过程,返回一个记录集:
_RecordsetPtr m_pRecordSetTemp;
m_pRecordSetTemp.CreateInstance("ADODB.Recordset");
#ifdef _DEBUG
if (m_pRecordSetTemp== NULL)
{
AfxMessageBox("RecordSet 对象创建失败! 请确认是否初始化了COM环境.");
}
#endif
_CommandPtr m_pCommand;
m_pCommand.CreateInstance(__uuidof(Command));
#ifdef _DEBUG
if (m_pCommand == NULL)
{
AfxMessageBox("Command 对象创建失败! 请确认是否初始化了COM环境.");
}
#endif
ASSERT(m_pCommand != NULL);
//输入参数 Member
_ParameterPtr pParamMember;
pParamMember.CreateInstance("ADODB.Parameter");
pParamMember->Name="member"; //所用存储过程参数名称
pParamMember->Type=adChar; //参数类型
pParamMember->Size=32; //参数大小
pParamMember->Direction=adParamInput;//表明是输入参数
pParamMember->Value=_variant_t(member);
m_pCommand->Parameters->Append(pParamMember);
//执行存储过程
m_pCommand->ActiveConnection=m_pConnection;
m_pCommand->CommandText="GetreMsgFromService"; //存储过程名称
m_pCommand->CommandType=adCmdStoredProc;//表示为存储过程adCmdStoredProc
int recordcount;
try
{
m_pRecordSetTemp=m_pCommand->Execute(NULL, NULL, adCmdStoredProc);
while(!m_pRecordSetTemp->adoEOF)
{
AfxMessageBox((LPCTSTR)(_bstr_t)m_pRecordSetTemp->GetCollect("reMsg"));
m_pRecordSetTemp->MoveNext();
recordcount=recordcount+1;
}
}
catch(_com_error e)
{
CString temp;
temp.Format(_T("Warning: 打开记录集发生异常. 错误信息: %s; 文件: %s; 行: %d/n"), e.ErrorMessage(), __FILE__, __LINE__);
AfxMessageBox(temp);
}
return m_pRecordSetTemp;
m_pRecordSetTemp->Close();
在这用m_pRecordSetTemp->GetRecordCount()来获取记录条数没有用.
2.VC执行一个不带参数的存储过程,返回一个记录集:
m_pRecordSet.CreateInstance("ADODB.Recordset");
#ifdef _DEBUG
if (m_pRecordSet == NULL)
{
AfxMessageBox("RecordSet 对象创建失败! 请确认是否初始化了COM环境.");
return;
}
#endif
ASSERT(m_pRecordSet != NULL);
CString sql="TestGet";
int i,recordcount;
try
{
m_pRecordSet->Open((_variant_t)sql,_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdStoredProc);
recordcount=m_pRecordSet->GetRecordCount();//Get records total.
if(!m_pRecordSet->adoEOF)
{
for(i=0;i<recordcount;i++)
{
AfxMessageBox((LPCTSTR)(_bstr_t)m_pRecordSet->GetCollect("Account"));
m_pRecordSet->MoveNext();
}
}
m_pRecordSet->Close();
}
catch(_com_error e)
{
CString temp;
temp.Format(_T("Warning: 打开记录集发生异常. 错误信息: %s; 文件: %s; 行: %d/n"), e.ErrorMessage(), __FILE__, __LINE__);
AfxMessageBox(temp);
}
如果不用存储过程将sql变量改成sql语句就可以了.
3.VC执行一个带参数的存储过程,返回单个值:
CString retu;
m_pCommand.CreateInstance("ADODB.Command");
#ifdef _DEBUG
if (m_pCommand == NULL)
{
AfxMessageBox("Command 对象创建失败! 请确认是否初始化了COM环境.");
}
#endif
ASSERT(m_pCommand != NULL);
//输入参数 Member
_ParameterPtr pParamMember;
pParamMember.CreateInstance("ADODB.Parameter");
pParamMember->Name="member"; //所用存储过程参数名称
pParamMember->Type=adChar; //参数类型
pParamMember->Size=32; //参数大小
pParamMember->Direction=adParamInput;//表明是输入参数
pParamMember->Value=_variant_t(member);
m_pCommand->Parameters->Append(pParamMember);
//返回值
_ParameterPtr pParamOk;
pParamOk.CreateInstance("ADODB.Parameter");
pParamOk->Name="welcome"; //参数2名称
pParamOk->Type=adChar; //字符串
pParamOk->Size=70; //大小为70个字节
pParamOk->Direction=adParamOutput; //声明是输出参数
m_pCommand->Parameters->Append(pParamOk);
//执行存储过程
m_pCommand->ActiveConnection=m_pConnection;
m_pCommand->CommandText="GetWelcome"; //存储过程名称
m_pCommand->CommandType=adCmdStoredProc;//表示为存储过程adCmdStoredProc
m_pCommand->Execute(NULL, NULL, adCmdStoredProc);
retu=(char*)_bstr_t(pParamOk->Value);
pParamMember->Release();
return retu;
- VC执行存储过程
- VC执行存储过程
- VC执行存储过程
- VC执行存储过程
- VC执行存储过程
- VC中执行存储过程
- 在VC++程序中显示存储过程的执行进度
- vc++中,ado执行sql server存储过程
- VC ado调用oracle执行存储过程获取记录集
- VC ado调用oracle执行存储过程获取记录集
- vc中ADO执行存储过程方法记录
- VC存储过程
- VC调用存储过程
- VC存储过程
- vc 存储过程
- VC存储过程
- SqlCommand执行存储过程
- C#执行存储过程
- Spring 的优秀工具类盘点,第 2 部分: 特殊字符转义和方法入参检测工具类
- linux egrep新添的正则表达式元字符
- “大数据”的本质是互联网智商的提升
- Linux知识积累:Ubuntu下,硬盘分区挂载
- Unable to compile class for JSP 装饰器
- VC执行存储过程
- 嵌入式linux环境视频采集知识(V4L2)
- 链路层套接字PF_PACKET简介
- Java项目开发规范之方法命名规范
- gdb 调试方法
- window 操作系统下的读写错误
- 室内装修
- XML中转义
- LNK2001错误排除