Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use DAO in Visual C++??

Status
Not open for further replies.

conio96

Programmer
Dec 5, 2002
4
0
0
MY
Hi, I'm trying to implement a database application with Visual C++ and DAO.

I have found out from internet that I need to install the SDK in order to use the DAO. So, I have install the DAOSDK from my Visual C++ CD. I received the following message when I include dbdao.h to my program.
The DAOSDK 3.5 libraries will not operate correctly if built with MFC older than 4.2

So, I went to the C:\Program Files\Microsoft Visual Studio\VC98\MFC\Lib, I found out that I'm using MFC42.lib. The header file said that the version of the MFC can be >= 4.2, but why I received that error??

Is there any other steps that I have missed out in order to use DAO with Visual C++? Please advice.

Thank you in advance.
 
This is a short sample:
Code:
//using DAO
#import "G:\Program Files\Common Files\Microsoft Shared\DAO\dao360.dll"
#include "Debug\dao360.tlh"
#include<atlbase.h>
#include<iostream>

using namespace std;

int main()
{
    CoInitialize(0);
    {
        HRESULT hr = -1;
        CComPtr<IUnknown> app;
        DAO::_DBEngine* eng;
        DAO::Workspace* wr;
        DAO::Database* db;
        DAO::Recordset* rs;
        VARIANT_BOOL eof;
        VARIANT_BOOL bof;
        DAO::Fields* fs;
        DAO::_Field* f1;
        DAO::_Field* f2;
        hr = app.CoCreateInstance(L&quot;DAO.DBEngine.36&quot;);
        hr = app->QueryInterface(&eng);
        hr = eng->raw_CreateWorkspace(L&quot;TestWorkSpace1&quot;, L&quot;Admin&quot;, L&quot;&quot;, _variant_t(DAO::dbUseJet), &wr);
        //open dbname, ifexclusive, ifreadonly, connect, retdb
        hr = wr->raw_OpenDatabase(_bstr_t(L&quot;c:\\db1.mdb&quot;), _variant_t(0), _variant_t(0), _variant_t(L&quot;&quot;), &db);
        hr = db->raw_OpenRecordset(_bstr_t(L&quot;select * from Table1&quot;), 
            _variant_t(DAO::dbOpenDynaset), _variant_t(0), _variant_t(2), &rs);
        hr = rs->get_Fields(&fs);
        hr = fs->get_Item(_variant_t(0), &f1);
        hr = fs->get_Item(_variant_t(1), &f2);
        wcout<< L&quot;<&quot;<< (BSTR)f1->Name<< L&quot;><&quot; << f2->Name<< L&quot;>&quot;<< endl;
        VARIANT valx, valy;
        while(true)
        {
            hr = rs->get_EOF(&eof);
            hr = rs->get_BOF(&bof);
            if(eof)break;
            if(bof)break;
            f1->get_Value(&valx);
            f2->get_Value(&valy);
            wcout<< L&quot;{&quot;<< (wchar_t*)_bstr_t(_variant_t(valx))<< L&quot;}{&quot;;
            wcout<< (wchar_t*)_bstr_t(_variant_t(valy))<< L&quot;}&quot;<< endl;
            hr = rs->MoveNext();
        }

        hr = hr;
       
    }
    CoUninitialize();
    
    return 0;
}

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top