Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CRecordset and .Insert()

Posted on 2002-03-06
4
Medium Priority
?
462 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 400 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Loops Section Overview
Suggested Courses

886 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