Solved

Recordset by SQL in MFC, from record to record ...

Posted on 2001-08-30
10
609 Views
Last Modified: 2013-11-25
The question about MFC C++ or MS Windows C++ for
Database managment.
For example: You have database ( MDB or SQL )
1) How to open recordset by SQL in MFC C++?
2) If recordset open, then how to go from record to record to update recordset?
3) How to delete, insert, select recordset in C++.
Please propose a web link to examle or something else.
Alex.
0
Comment
Question by:ua1zcl
[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
10 Comments
 
LVL 1

Accepted Solution

by:
mupchu777 earned 100 total points
ID: 6442997
Well Im going to give you three solutions here:

1st:  You can use OLEDB consumer templates

I'd give code but it would fill a couple of pages...

http://www.msdn.microsoft.com

Just look at the msdn site and look for
FAQ: Using the OLE DB Consumer Templates

Most of your questions can be answered there.  You may want to spend sometime at msdn looking at what they are as well (basically a templated class that simplifies getting data with OLEDB).  

2nd:  You can use ADO

You really only have to use the #import command on the ado library (msado15.dll).  Just remember to change eof to EOF

see http://www.devx.com/free/mgznarch/vcdj/1998/jan98/ado2.asp

and also Articles Q169496 and Q174565 in the Microsoft Knowledge Base

3rd You can use DAO (I don't recommend it)

MFC has its own DAO classes for dealing with recordsets and such.

The basic gist of the way to read data is:

// open database
CDaoDatabase oDb;
CDaoRecordset oRs(&oDb);

oDb.Open(strDataPath); // path to database
               
// execute query
oRs.Open(dbOpenDynaset,"SELECT * from Logs", dbOpenDynaset); // the last parameter determines if you can edit

if (!oRs.IsEOF())
     oRs.MoveFirst();

while (!(oRs.IsEOF()))
{
     COleVariant vValue1;
     COleVariant vValue2;
     COleVariant vValue3;

     // timestamp
     vValue1.vt = VT_DATE;
     oRs.GetFieldValue("EnterTime", vValue1);
     vValue2.vt = VT_BSTR;
     oRs.GetFieldValue("Type", vValue2);
     vValue3.vt = VT_BSTR;
     oRs.GetFieldValue("Msg", vValue3);

     if (vValue1.vt != VT_DATE)
     vValue1.ChangeType(VT_DATE);

     ...
     ...

     etc

     oRs.MoveNext();
}

oRs.Close();
oDb.Close();

also to edit and update a record use the Edit, Update and AddNew member functions of the recordset (note Update must be called after Edit and AddNew to update the record)


hope this helps
0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 6443093
What about MFC's CDatabase and CRecordset classes?  

That way, you can use ClassWizard's support for creating the DB classes for you and binding the columns to data members.  The CRecordset contains methods to easily Insert, Edit, and Delete rows in a database.  Not the fastest at runtime, but pretty quick to implement.

-=- James.
0
 
LVL 1

Author Comment

by:ua1zcl
ID: 6444140
Mupchu777 and James(jtwine), thank to both. I not accept
any answer until few days let me see for all i got.
Excuse me, but i must rejcet Mupchu777 answer for some time, that is e-e recomendations.
 
0
Industry Leaders: 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!

 
LVL 1

Author Comment

by:ua1zcl
ID: 6444147
Mupchu777 and James(jtwine), thank to both. I not accept
any answer until few days let me see for all i got.
Excuse me, but i must rejcet Mupchu777 answer for some time, that is e-e recomendations.
 
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6449239
ua1zcl,
I agree with jtwine that CRecordset/CDatabase is the easiest way to get started.  Would you like a step-by-step instruction guide?

-- Dan
0
 
LVL 1

Author Comment

by:ua1zcl
ID: 6453323
I accept mupchu777  answer. Thanks a lot.
I can't find a button to press to accept an answer
for now.
0
 
LVL 1

Expert Comment

by:mupchu777
ID: 6454701
I think if I make another comment you can accept that as an answer.  You can't accept my old answer as you have already rejected it.

I would also clarify that yes CDatabase and CRecordset are options as well.  It is syntaticly similar to CDAODatabase and CDAORecordset.  Personally I would avoid the MFC classes and use ADO (through the import command), but that is just my preference.  The only thing I could really argue is the programming model of ADO coupled with a fairly tight wrapper with little overhead.

0
 
LVL 1

Author Comment

by:ua1zcl
ID: 6455450
I am new in data base programming and can not
anythig argue against. So, thank you , hope meet you again here.
Alex.
0
 
LVL 11

Expert Comment

by:griessh
ID: 6865627
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to accept "mupchu777" comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: http://www.experts-exchange.com/commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6886446
Per recommendation, force-accepted by
Netminder
Community Support Moderator
Experts Exchange
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

Title # Comments Views Activity
How can i Install a new Data Source on Visual Studio 2 122
Which Linux flavors will this run on? 6 116
max float value 3 77
c++, dynamic object by json 1 65
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

710 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