locked
MFC Dao -> ADO - Problems RRS feed

  • Question

  • Hello,

    I'm currently in a traineeship as a software engineer and this is my first time handling MFC and I have some difficulitys
    converting the Dao interface to ADO.

    The following code shows how I initialise a record set

    rs->Open("SELECT * FROM Gesamt",Global::MyDatabase->GetActiveConnection().GetInterfacePtr(),adOpenStatic,
                    adLockReadOnly,adCmdText);

    This is working just fine.

    I have the following problems:

    Count

    rs->GetRecordCount();

    This does not work. I've tried changing the CursorType and anything I can think of aswell.
    The table contains 800 000 rows.

    DoDataExchange

    My biggest problem is assigning the cell values to the member variables.
    This is a working Dao-Code:

    void CJapRecordsets::DoFieldExchange(CDaoFieldExchange* pFX)
    {
        //{{AFX_FIELD_MAP(CJapRecordsets)
        pFX->SetFieldType(CDaoFieldExchange::outputColumn);
        DFX_Text(pFX, _T("[NAME1]"), m_NAME1);
        DFX_Text(pFX, _T("[VORNAME1]"), m_VORNAME1);
        DFX_Text(pFX, _T("[NAME2]"), m_NAME2);
        DFX_Text(pFX, _T("[VORNAME2]"), m_VORNAME2);
        DFX_Text(pFX, _T("[ARTIKEL]"), m_ARTIKEL);
        DFX_Text(pFX, _T("[TITEL]"), m_TITEL);
        DFX_Text(pFX, _T("[UNTERTITEL]"), m_UNTERTITEL);
        DFX_Text(pFX, _T("[AUFLAGE]"), m_AUFLAGE);
        DFX_Text(pFX, _T("[ORT]"), m_ORT);
        DFX_Text(pFX, _T("[JAHR]"), m_JAHR);
        DFX_Text(pFX, _T("[BJAHR]"), m_BJAHR);
        DFX_Text(pFX, _T("[FORMAT]"), m_FORMAT);
        DFX_Text(pFX, _T("[ILLUSTRA]"), m_ILLUSTRA);
        DFX_Text(pFX, _T("[EINBAND]"), m_EINBAND);
        DFX_Text(pFX, _T("[BEIGABEN]"), m_BEIGABEN);
        DFX_Text(pFX, _T("[NACHWEIS]"), m_NACHWEIS);
        DFX_Text(pFX, _T("[ZUSTAND]"), m_ZUSTAND);
        DFX_Text(pFX, _T("[WÄHRUNG]"), m_W_HRUNG);
        DFX_Single(pFX, _T("[ZUSCHLAG]"), m_ZUSCHLAG);
        DFX_Text(pFX, _T("[SIGEL]"), m_SIGEL);
        DFX_Text(pFX, _T("[KENNZ]"), m_KENNZ);
        DFX_Double(pFX, _T("[SORT]"), m_SORT);
        DFX_Byte(pFX, _T("[JAP]"), m_JAP);
        DFX_Bool(pFX, _T("[MYLISTFLAG]"), m_MYLISTFLAG);
        DFX_Long(pFX, _T("[ID]"), m_ID);
        //}}AFX_FIELD_MAP
    }


    I just cannot get this function working for ADO - ofc I did change the declaration and the parameter and tried using
    DDX_...I couldn't get it to work though.
    Additionaly, it does not trigger automatically.

    Dao does trigger the event automatically everytime the recordset is being opened.

    I hope you can help me in any way.

    Looking forward to see your replys.
    Thanks.


    • Edited by Basix_Dev Monday, February 20, 2012 10:14 AM
    Monday, February 20, 2012 10:14 AM

Answers

  • Hello,

    Generally speaking, the error of 3105 is caused by the field names are not match, or the date type and length are not match.

    I would suggest you to check these in your codes, because we do not have the data in your site.

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    The error occurs when executing this simple select query.

    I'm neither updating/insert wrong data types nor working with wrong fieldnames since I'm trying to select everything from the table(*).

    Here's a link to the database so you can take a look at the structure ...

    http://www.mediafire.com/?c96tb0dwtkda22d

    Ofc,I've already tried to google this errorcode and tried to use the offered solutions. However, I did not find any working method. I cannot tell why the Dispatch error occurs when I'm simply trying to execute a SELECT * FROM statement.


    ----------------------------------------------------------------------------------------------------------------------------

    The only thing I had to chance was the query that was opening the recordset. It seems that 4 columns caused the error, so it was most likely database related, not program related.

    • Edited by Basix_Dev Tuesday, February 28, 2012 10:42 AM
    • Marked as answer by Basix_Dev Tuesday, February 28, 2012 10:42 AM
    Wednesday, February 22, 2012 9:31 AM

All replies

  • Basix_Dev wrote:
    >
    >The following code shows how I initialise a record set
    >rs->Open("SELECT * FROM Gesamt",Global::MyDatabase->GetActiveConnection().GetInterfacePtr(),adOpenStatic,
    >                adLockReadOnly,adCmdText);
    >
    >This is working just fine.
    >
    >I have the following problems:
    >
    >Count rs->GetRecordCount();
    >
    >This does not work. I've tried changing the CursorType and anything I can think of aswell.
     
    Right.  GetRecordCount is not all that useful, because the value is not
    reliable unless you have already read through all of the records.  Remember
    that it can't know the record count until all of the records have been
    transferred from the database, and for efficiency, it doesn't load all
    800,000 records before it begins running through them.
     
    If you need to know how many records there are, do a "SELECT count(*) FROM
    Gesamt" before you do this query.
     
    >DoDataExchange
    >
    >My biggest problem is assigning the cell values to the member variables.
    >This is a working Dao-Code:
    >...
    >I just cannot get this function working for ADO - ofc I did change the
    >declaration and the parameter and tried using DDX_...I couldn't get it
    >to work though.
     
    What does your code look like now?  Are you calling MoveNext to move from
    row to row?
    --
    Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.
     

    Tim Roberts, VC++ MVP Providenza & Boekelheide, Inc.
    Tuesday, February 21, 2012 5:20 AM
  • Right.  GetRecordCount is not all that useful, because the value is not
    reliable unless you have already read through all of the records.  Remember
    that it can't know the record count until all of the records have been
    transferred from the database, and for efficiency, it doesn't load all
    800,000 records before it begins running through them.
     
    If you need to know how many records there are, do a "SELECT count(*) FROM
    Gesamt" before you do this query.
     
    What does your code look like now?  Are you calling MoveNext to move from
    row to row?

    I already thought about using a query to get the record count (SELECT COUNT(*)) - this should not be a huge problem.

    CJapRecordsets is a class with membervariables that inherits from _RecordsetPtr.

    I'm not sure if it should inherit _RecordsetPtr or CADORecordset.

    I did try to change it to CADORecordset(this seems to be working out better - there are functions that do not exist in _RecordsetPtr even though I need them). However I get an IDispatch Error #3105 here...

    			rs = new CJapRecordsets(Global::MyDatabase);
    
    		if(!Global::MyDatabase->IsOpen())					
    		{
    					Global::MyDatabase->Open("Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=C:\JAP-MAIN.sdf;");	
    		}
    		
    		
    
    		if(!rs->IsOpen())
    		{
    			// This causes the IDispatch error	
    			rs->Open(Global::MyDatabase->GetActiveConnection().GetInterfacePtr(),"SELECT * FROM Gesamt", 1);
    		}

    I can open the database successfully and check if the recordset is open or closed. However, upon trying to execute a select query, I keep getting an IDispatch error.

    #include "stdafx.h"
    #include "JAP.h"
    #include <htmlhelp.h>
    #include "JapRecordsets.h"
    
    
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    
    /////////////////////////////////////////////////////////////////////////////
    // CJapRecordsets
    
    IMPLEMENT_DYNAMIC(CJapRecordsets, CJapRecordsets)
    
    CJapRecordsets::CJapRecordsets(CADODatabase* pdb)
    	: CADORecordset(pdb)
    {
    
    	m_NAME1 = _T("");
    	m_VORNAME1 = _T("");
    	m_NAME2 = _T("");
    	m_VORNAME2 = _T("");
    	m_ARTIKEL = _T("");
    	m_TITEL = _T("");
    	m_UNTERTITEL = _T("");
    	m_AUFLAGE = _T("");
    	m_ORT = _T("");
    	m_JAHR = _T("");
    	m_BJAHR = _T("");
    	m_FORMAT = _T("");
    	m_ILLUSTRA = _T("");
    	m_EINBAND = _T("");
    	m_BEIGABEN = _T("");
    	m_NACHWEIS = _T("");
    	m_ZUSTAND = _T("");
    	m_W_HRUNG = _T("");
    	m_ZUSCHLAG = 0.0f;
    	m_SIGEL = _T("");
    	m_KENNZ = _T("");
    	m_SORT = 0.0;
    	m_JAP = 0;
    	m_MYLISTFLAG = FALSE;
    	m_ID = 0;
    	m_nFields = 25;
    
    	m_nDefaultType = 0;
    }
    
    
    CString CJapRecordsets::GetDefaultDBName()
    {
    	return _T(".\\JAP-MAIN.sdf");
    }
    
    CString CJapRecordsets::GetDefaultSQL()
    {
    	return _T("SELECT * FROM [Gesamt]");
    }
    
    void CJapRecordsets::DoDataExchange(CDataExchange* pDX) 
    {
    		
    // Currently empty, must be changed later, dno how though
    // Member variables must be asigned
    // m_NAME1 must be the cell value of the column "NAME1"
    }
    
    /////////////////////////////////////////////////////////////////////////////
    // Diagnose CJapRecordsets
    
    #ifdef _DEBUG
    void CJapRecordsets::AssertValid() const
    {
    //	CADORecordset::AssertValid();
    }
    
    void CJapRecordsets::Dump(CDumpContext& dc) const
    {
    //	CADORecordset::Dump(dc);
    }
    #endif //_DEBUG</htmlhelp.h>


    • Edited by Basix_Dev Tuesday, February 21, 2012 8:35 AM
    Tuesday, February 21, 2012 8:34 AM
  • Hello,

    Generally speaking, the error of 3105 is caused by the field names are not match, or the date type and length are not match.

    I would suggest you to check these in your codes, because we do not have the data in your site.

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, February 22, 2012 3:13 AM
    Moderator
  • Hello,

    Generally speaking, the error of 3105 is caused by the field names are not match, or the date type and length are not match.

    I would suggest you to check these in your codes, because we do not have the data in your site.

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    The error occurs when executing this simple select query.

    I'm neither updating/insert wrong data types nor working with wrong fieldnames since I'm trying to select everything from the table(*).

    Here's a link to the database so you can take a look at the structure ...

    http://www.mediafire.com/?c96tb0dwtkda22d

    Ofc,I've already tried to google this errorcode and tried to use the offered solutions. However, I did not find any working method. I cannot tell why the Dispatch error occurs when I'm simply trying to execute a SELECT * FROM statement.


    ----------------------------------------------------------------------------------------------------------------------------

    The only thing I had to chance was the query that was opening the recordset. It seems that 4 columns caused the error, so it was most likely database related, not program related.

    • Edited by Basix_Dev Tuesday, February 28, 2012 10:42 AM
    • Marked as answer by Basix_Dev Tuesday, February 28, 2012 10:42 AM
    Wednesday, February 22, 2012 9:31 AM