Can I use a CRecordset dervived class without a database?

Owen Ransen 541 Reputation points
2021-10-21T16:30:38.137+00:00

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++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,540 questions
Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
823 questions
0 comments No comments
{count} votes

Accepted answer
  1. Owen Ransen 541 Reputation points
    2021-10-22T07:23:03.787+00:00

    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();
    

    };

    0 comments No comments

0 additional answers

Sort by: Most helpful