We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

CRecordset::Addnew

thebestdave76
on
Medium Priority
1,201 Views
Last Modified: 2013-11-20
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"?
Comment
Watch Question

mahesh1402IT Professional
Top Expert 2005

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

you can do like :

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

MAHESH

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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

Author

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?
AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT
Commented:
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

Author

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?
IT Professional
Top Expert 2005
Commented:
>>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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.