Solved

CRecordset and .Insert()

Posted on 2002-03-06
4
437 Views
Last Modified: 2013-11-20
Hi, I am using CRecordset and OLE DB

I have created it using an MFC exe wizard
and have added ATL support

I have added an ATL consumer for the database, I have created it one time with CTable and one time with CCommand (and both are not doing what I want)

I can read from the DB, and I can write to existing records and update them, but I cannot add a new record.

I have added support for update, insert and delete.

So that is where I am at, I will be glad to include any code you like, everything seems to be working good, but the the HRESULT returned by CRecordset.Insert() always tests true for FAILED()



please help me!!!

thanks
Bob

ps, will gladly add more points for good "explaination"
0
Comment
Question by:bebonham
  • 3
4 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 100 total points
ID: 6845426
Please show code for your insert function.
0
 
LVL 8

Author Comment

by:bebonham
ID: 6845490
void CDb2Dlg::OnOK()
{

///
CBorrower cb;
///this is the subclass (right term?) of CRecordset

cb.Open();
cb.MoveFirst();
///
AfxMessageBox(cb.m_FirstName);
///this works, it alerts me the name of the first person in the db.

///
if(FAILED(cb.Insert())){
     AfxMessageBox("failed");
}
///failed is always popping up here

strcpy(cb.m_ID,"thespecial123");    
strcpy(cb.m_FirstName,"Bob");
strcpy(cb.m_LastName,"Bonham");
cb.Update();

CDialog::OnOK();
}


thanks for your prompt attention
0
 
LVL 8

Author Comment

by:bebonham
ID: 6845545
jhance, I have wasted your time.

Unfortunately, I did not do as thorough a job as I should have when reading the docs :(

but you, as always, got me thinking, and I found my answer, THANKS!!

what I did wrong is simple, I have to set all the datas first, like
strcpy(cb.m_LastName, "SMITH");
and THEN I call
cb.Insert();
not cb.Insert() first.

so, I would have never got that unless you pointed me that it was the insert code that was the problem.

Thanks,
I'll be back for more help soon,

Bob
0
 
LVL 8

Author Comment

by:bebonham
ID: 6845549
thanks for the help / attention to my question.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Need to retreive data from .TFS file exported by DVR 8 166
Rewrite URL With Encoded Characters 6 64
if loop in java 3 114
noX challenge 17 77
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 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

19 Experts available now in Live!

Get 1:1 Help Now