DoFieldExchange and Predefined Queries (ODBC) 
Author Message
 DoFieldExchange and Predefined Queries (ODBC)

Hello,

I've been having some troubles with executing stored procedures on an MS SQL
7 server.

When using CDatabase::ExecuteSQL() it works fine, and I am able to pass
parameters to this method. Everything in this situtation works according to
what we want.

However, when I try following the recipe in the MSDN help article "Declaring
a Class for a Predifined Query (ODBC)", I run into some problems.

Details:
-All I want is one value, (in the future, maybe a series of values of the
same type), such as an ID out of a Table.
-I want to pass 1 or more paramters to the stored procedure

A badass exception occurs when I do the above following the recipe.

Code snippets (according to recipe):
------------------------
class CRSPQAgent : public CRecordset

CRSPQAgent::CRSPQAgent(CDatabase* pdb)
 : CRecordset(pdb)
{
 //{{AFX_FIELD_INIT(CRSPQAgent)
 m_AgentID = 0;
 m_MasterID = 0;
 m_IPAddress = _T("");
 m_CalibrationData = _T("");
 m_Settings = 0;
 m_Blank1 = _T("");
 m_Blank2 = _T("");
 m_nFields = 7;
//}}AFX_FIELD_INIT

 m_nDefaultType = snapshot;
 m_nParams += 1;
 m_strIPAddressParam = _T("");

Quote:
}

void CRSPQAgent::DoFieldExchange(CFieldExchange* pFX)
{
 //{{AFX_FIELD_MAP(CRSPQAgent)
 pFX->SetFieldType(CFieldExchange::outputColumn);
 RFX_Long(pFX, _T("[AgentID]"), m_AgentID);
 RFX_Int(pFX, _T("[MasterID]"), m_MasterID);
 RFX_Text(pFX, _T("[IPAddress]"), m_IPAddress);
 RFX_Text(pFX, _T("[CalibrationData]"), m_CalibrationData);
 RFX_Long(pFX, _T("[Settings]"), m_Settings);
 RFX_Text(pFX, _T("[Blank1]"), m_Blank1);
 RFX_Text(pFX, _T("[Blank2]"), m_Blank2);
 //}}AFX_FIELD_MAP

 //additions for parameter:
 pFX->SetFieldType(CFieldExchange::inputParam);
 RFX_Text(pFX, "ipaddress", m_strIPAddressParam);

Quote:
}

Using the object
...
 if (!m_bDatabaseOpened)
  return;

 strSQL = "{CALL Test3 (?)}"; //execute through a CRecordSet Derived Object
 prspqAgentQuery = new CRSPQAgent(&m_database);
 prspqAgentQuery->m_strIPAddressParam = pResponse->GetIPAddress();
 try
 {
  prspqAgentQuery->Open(CRecordset::snapshot, strSQL);  //unhandled
exception here
 }
 catch(CDBException * e)
 {
        AfxMessageBox(e->m_strError, MB_ICONEXCLAMATION);
        delete prspqAgentQuery;
          prspqAgentQuery = NULL;
        e->Delete();
 }
------------------------
The de{*filter*} breaks and takes me to line 1200 of DBRFX.CPP in the function:
void AFXAPI RFX_Long(CFieldExchange* pFX, LPCTSTR szName, long& value):

Currently I can deal with executing the SQL directly, but in the near future
this will not suffice.
Please, if you have suggestions, successes, failures, let me know.
Thanks in advance.
-Chris



Sat, 26 Jul 2003 05:07:15 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Predefined Queries (ODBC)

2. Problem sorting predefined query using ODBC

3. Predefined Queries and DAO

4. CRecordset-Predefined query calling VB code

5. CRecordset: predefined queries with parameters that have an apostrophe

6. CRecordset - parameterized predefined queries/stored procedures

7. how to write to table without predefined fields (odbc mfc)

8. Basic ODBC Database Query

9. ODBC Error : "Query is too complex"

10. ODBC Error: Operation must use an updatable query.

11. Calling a Query in MSAccess from ODBC?

12. Select query on LongBinary data types, MFC ODBC

 

 
Powered by phpBB® Forum Software