找遍CSDN,未找到正确解答 MFC ODBC调用存储过程返回参数的答案,该怎么处理
找遍****,未找到正确解答 MFC ODBC调用存储过程返回参数的答案
存储过程如下:一个输入参数,一个输出参数 anywhere 7数据库
ALTER procedure DBA.test(in aa varchar(15),out open_time varchar(15))
begin
declare @sqlstate varchar(5);
declare @op2 timestamp;
select b.ci_user_id into open_time
from
ac_customer_info as b where
b.ci_address = aa and b.ci_status = 1;
message STRING( 'opw = ',open_time) type info to client
exception //return
when others then
select sqlstate into @sqlstate;
message STRING( 'SQLSTATE = ',@sqlstate) type info to client
end
在一个**** FAQ中的解答中说
CDatabase * pDatabase = new CDatabase;
pDatabase-> OpenEx( "DSN=ODBCName;UID=***;PWD=*** ", 0 );
CRecordset rs( pDatabase );
SQL.Format( "{Test %d,%d,%d,%d} ",Time0, Time1, Time2, Time3);
rs.Open( CRecordset::dynamic, SQL, CRecordset::none );
rs.GetFieldValue( (long)0, strReturn );
rs.Close();
pDatabase-> Close();
delete pDatabase;
做了测试,但是rs.Open( CRecordset::dynamic, SQL, CRecordset::none ); 这一句话通过不了,提示是ODBC不支持动态指针.
另外有一种方案是做一个新的Crecordset类来处理,我贴一下我的代码
chcode.h
#include <afxdb.h>
/////////////////////////////////////////////////////////////////////////////
// Cchcode recordset
class Cchcode : public CRecordset
{
public:
void Move( long nrows, WORD wfetchtype);
Cchcode(CDatabase* pDatabase = NULL);
DECLARE_DYNAMIC(Cchcode)
// Field/Param Data
//{{AFX_FIELD(Cchcode, CRecordset)
CString m_roomid;
CString m_userid;
//}}AFX_FIELD
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(Cchcode)
public:
virtual CString GetDefaultConnect(); // Default connection string
virtual CString GetDefaultSQL(); // Default SQL for Recordset
virtual void DoFieldExchange(CFieldExchange* pFX); // RFX support
//}}AFX_VIRTUAL
// Implementation
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
存储过程如下:一个输入参数,一个输出参数 anywhere 7数据库
ALTER procedure DBA.test(in aa varchar(15),out open_time varchar(15))
begin
declare @sqlstate varchar(5);
declare @op2 timestamp;
select b.ci_user_id into open_time
from
ac_customer_info as b where
b.ci_address = aa and b.ci_status = 1;
message STRING( 'opw = ',open_time) type info to client
exception //return
when others then
select sqlstate into @sqlstate;
message STRING( 'SQLSTATE = ',@sqlstate) type info to client
end
在一个**** FAQ中的解答中说
CDatabase * pDatabase = new CDatabase;
pDatabase-> OpenEx( "DSN=ODBCName;UID=***;PWD=*** ", 0 );
CRecordset rs( pDatabase );
SQL.Format( "{Test %d,%d,%d,%d} ",Time0, Time1, Time2, Time3);
rs.Open( CRecordset::dynamic, SQL, CRecordset::none );
rs.GetFieldValue( (long)0, strReturn );
rs.Close();
pDatabase-> Close();
delete pDatabase;
做了测试,但是rs.Open( CRecordset::dynamic, SQL, CRecordset::none ); 这一句话通过不了,提示是ODBC不支持动态指针.
另外有一种方案是做一个新的Crecordset类来处理,我贴一下我的代码
chcode.h
#include <afxdb.h>
/////////////////////////////////////////////////////////////////////////////
// Cchcode recordset
class Cchcode : public CRecordset
{
public:
void Move( long nrows, WORD wfetchtype);
Cchcode(CDatabase* pDatabase = NULL);
DECLARE_DYNAMIC(Cchcode)
// Field/Param Data
//{{AFX_FIELD(Cchcode, CRecordset)
CString m_roomid;
CString m_userid;
//}}AFX_FIELD
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(Cchcode)
public:
virtual CString GetDefaultConnect(); // Default connection string
virtual CString GetDefaultSQL(); // Default SQL for Recordset
virtual void DoFieldExchange(CFieldExchange* pFX); // RFX support
//}}AFX_VIRTUAL
// Implementation
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif