CRecordset::Addnew

Hi,

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

      Champ="Simu1";
               Test="ee";
      RecDonnees.Open(CRecordset::dynaset,                  "SELECT * FROM MERSENNE");

      RecDonnees.AddNew();
      RecDonnees(Champ)=Test;
      RecDonnees.Update();
}

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"?
thebestdave76Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

you can do like :

     RecDonnees.AddNew();
     RecDonnees.Champ=Test;
     RecDonnees.Update();

MAHESH
0
rajeev_devinCommented:
0
thebestdave76Author Commented:
I tried RecDonnees.Champ=Test;
I had this message :
error C2039: 'Champ' : is not a member of 'CRecordset'
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

thebestdave76Author Commented:
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?
0
AndyAinscowFreelance programmer / ConsultantCommented:
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.Edit();
rs.m_sChamp = "Test";
rs.Update();

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.
www.codeproject.com/database/caaadoclass1.asp
0
thebestdave76Author Commented:
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?
0
mahesh1402Commented:
>>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 == > http://www.codeproject.com/database/caaadoclass1.asp?select=800391&df=100&forumid=2115&fr=356.5#xx800391xx

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)


MAHESH
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.