Solved

CRecordset and .Insert()

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iSeries DB2 Query 2 95
List out all word 7 288
method notes when mouse over in eclipse 5 86
how to use laptop or pad camera in vb.net windows application 2 70
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
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…

808 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