Solved

CRecordset and .Insert()

Posted on 2002-03-06
4
447 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.

738 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