Solved

CRecordset and .Insert()

Posted on 2002-03-06
4
445 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
ORA-01403: no data found 43 106
centeredAverage challenge 8 180
Way to decrease size of apk file 9 88
Problem to Office 1 18
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

820 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