Posted on 2006-03-21
Last Modified: 2013-11-20

I've got a database named "baseref". In this DB there is a table Named "MERSENNE". In this Table there is a column named "Simu1". I'd like to add a record in the table "MERSENNE" so I wrote this program :

CAleatoire::CAleatoire(CDatabase *baseRef)
      CString Test;
      CString Champ;
      CRecordset RecDonnees(baseRef);

      RecDonnees.Open(CRecordset::dynaset,                  "SELECT * FROM MERSENNE");


When I compile this program, the line "RecDonnees(Champ)=Test" is on error :

error C2064: term does not evaluate to a function

What have I have to do to add a record to my table "MERSENNE"?
Question by:thebestdave76
    LVL 22

    Expert Comment

    RecDonnees(Champ)=Test; <== this is wrong RecDonnees is not function.....

    you can do like :


    LVL 12

    Assisted Solution


    Author Comment

    I tried RecDonnees.Champ=Test;
    I had this message :
    error C2039: 'Champ' : is not a member of 'CRecordset'

    Author Comment

    To rajeev_devin :

    I checked your link but I have had the same error when I wrote "StrCopy(RecDonnees("Simu1"), "ee");"

    What can I do to insert a new record?
    LVL 43

    Assisted Solution

    The problem (as you may have discovered) is that the CRecordset class itself isn't designed for writing values into the recordset simply.

    The simple solution is to use the class wizard to create a new class, based on CRecordset and select the table you want as part of the wizard process.  Then you can use code like
    rs.m_sChamp = "Test";

    A more complex way is to write your own (generic) CRecordset based class which you code the data transfer functions yourself.

    A complete alternative is to forget about ODBC and use an alternative such as ADO.  That will allow you to write simple code like you tried to do.

    Author Comment

    I tried the alternative ADO but there is a lot of errors on msjro.tlh during the compilation.

    I don't have the class Wizard on my Visual C++, it is disabled.
    How can I do to select the table I want as part of my new class?
    LVL 22

    Accepted Solution

    >>I tried the alternative ADO but there is a lot of errors on msjro.tlh during the compilation.

    There is solution given for errors here == >

    Look at comments at the end of the article.

    #pragma warning (disable: 4146)
    #import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
    rename("EOF", "EndOfFile") \
    rename("ParameterDirectionEnum", "_ParameterDirectionEnum") \
    rename("DataTypeEnum", "_DataTypeEnum")
    #import "C:\Program Files\Common Files\System\ado\msjro.dll" \
    no_namespace \
    rename("ReplicaTypeEnum", "_ReplicaTypeEnum")
    using namespace ADODB;
    #pragma warning (default: 4146)


    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Suggested Solutions

    This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now