CRecordSet可以使用存储过程吗

zhsl12 2006-08-15 08:31:41
我使用MFC向导建立一个工程,在向导中连接了SQL数据库,最后生成了一个CRecordSet对象。请问各位我怎么使用这个CRecordSet对象调用存储过程,需要什么头文件等等
...全文
283 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lzd 2006-08-15
  • 打赏
  • 举报
回复
用Command.Execute
zhsl12 2006-08-15
  • 打赏
  • 举报
回复
没人知道吗
zhsl12 2006-08-15
  • 打赏
  • 举报
回复
CDatabase * pDatabase = new CDatabase;

pDatabase->OpenEx("DSN=ODBCName;UID=***;PWD=***", 0 );

CRecordset rs( pDatabase );

SQL.Format("{call Test('%d','%d','%d','%d')}",Time0, Time1, Time2, Time3);

rs.Open( CRecordset::dynamic, SQL, CRecordset::readOnly );

if(rs.IsBOF()==0)
rs.MoveFirst(); //报错:提取类型超出范围

while(rs.IsEOF()==0)
{
rs.GetFieldValue( (long)0, strReturn );

....

rs.MoveNext();
}

rs.Close();

pDatabase->Close();
delete pDatabase;
zhsl12 2006-08-15
  • 打赏
  • 举报
回复
谢谢
handsomerun 2006-08-15
  • 打赏
  • 举报
回复
一般来说,是用Command.Execute
执行存储过程的

另外,CRecordSet对象调用存储过程,
好像是可以的

去msdn看了一下
CRecordset::Open
virtual BOOL Open( UINT nOpenType = AFX_DB_USE_DEFAULT_TYPE, LPCTSTR lpszSQL = NULL, DWORD dwOptions = none );



lpszSQL

A string pointer containing one of the following:

A NULL pointer.


The name of a table.


An SQL SELECT statement (optionally with an SQL WHERE or ORDER BY clause).


A CALL statement specifying the name of a predefined query (stored procedure). Be careful that you do not insert whitespace between the curly brace and the CALL keyword.

看整个意思,好像是可以打开一个stored procedure的
不过俺也没做过,不熟悉,呵呵
zhsl12 2006-08-15
  • 打赏
  • 举报
回复
用CRecordSet的对象可以操作command吗?

4,018

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧