question

OwenRansen-2591 avatar image
0 Votes"
OwenRansen-2591 asked OwenRansen-2591 answered

Can I use a CRecordset dervived class without a database?

Seems a silly question, but I'm no database expert, so bear with me.

I have a CRecordset derived class which works fine, here is the header:

 #pragma once
    
 #include <afxdb.h>
 class CCctAssembliesRecSet: public CRecordset
 {
 public:
     CCctAssembliesRecSet(CDatabase* pdb = nullptr);
     CString m_csCct3dSAPCode; // System.String
     CString m_csDescrizione; // System.String
     CString m_csSimpleMatNameDELME; // System.String
     CString m_csQta; // System.String
     double m_LungA; // System.Double
     CString m_csTuboSAPCode; // System.String
     CString m_csDXF; // System.String
     CTime m_Data; // System.DateTime
     CString m_csUT; // System.String
    
     virtual CString GetDefaultSQL();
     virtual void DoFieldExchange(CFieldExchange* pFX);
     virtual CString GetDefaultConnect();
 };

But there are circumstances in which I gather the data member values far from the database part. Then I may or may not add the recordset into the database.


My question is: Can I use CCctAssembliesRecSet simply as a data holder, a class, without reference to an actual database?

I suppose I am asking if GetDefaultConnect() will be called when I'm not doing a Edit or AddNew.

I think that is what I'm asking. Because I've noticed that after an .Update the data members are not necessarily valid any more.

Apologies for the confusion of my question, I hope someone can see through the mud.







c++office-access-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

OwenRansen-2591 avatar image
0 Votes"
OwenRansen-2591 answered

I don't know why I did not think of this in the first place, have a class of just data and put that class in the CRecordset derived class. Seems to work, of course you have to change how DoFieldExchange works a bit, but easy enough:

 #pragma once
 #include <afxdb.h>
    
 // This helper class is useful when we need to gather the data without the database
 class CCctAsmData 
 {
 public:
     CCctAsmData () {}
     CString m_csCct3dSAPCode; // System.String
     CString m_csDescrizione; // System.String
     CString m_csQta; // System.String
     double m_LungA =0.0 ; // System.Double
     CString m_csTuboSAPCode; // System.String
     CString m_csDXF; // System.String
     CTime m_Data; // System.DateTime
     CString m_csUT; // System.String
 };
    
    
 class CCctAssembliesRecSet: public CRecordset
 {
 public:
     CCctAssembliesRecSet(CDatabase* pdb = nullptr);
    
     CCctAsmData m_JustData ; // Only has data members, no functions
    
     virtual CString GetDefaultSQL();
     virtual void DoFieldExchange(CFieldExchange* pFX);
     virtual CString GetDefaultConnect();

};


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.