本文介绍了如何在使用DAO的VC ++(MFC)访问中写入和读取多值字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



是否有人在使用DAO从MFC的访问中如何写入和读取多值字段的值?
可能吗? :-O

我正在使用Access版本2003.
请帮我...

Hi,

Does anyone how to write and read value of a multivalued field in access from MFC using DAO?
Is It Possible? :-O

I''m using Access version 2003.. i found everywhere for answer,i couldn''t find it :((

Pls Help me...

推荐答案

#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"DAO.DBEngine.36");

        hr = app->QueryInterface(&eng);

        hr = eng->raw_CreateWorkspace(L"TestWorkSpace1", L"Admin", L"", _variant_t(DAO::dbUseJet), &wr);
        //open dbname, ifexclusive, ifreadonly, connect, retdb
        hr = wr->raw_OpenDatabase(_bstr_t(L"c:\\db1.mdb"), _variant_t(0), _variant_t(0), _variant_t(L""), &db);
        hr = db->raw_OpenRecordset(_bstr_t(L"select * from Table1"),
            _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"<"<< (BSTR)f1->Name<< L"><" << f2->Name<< L">"<< 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"{"<< (wchar_t*)_bstr_t(_variant_t(valx))<< L"}{";
            wcout<< (wchar_t*)_bstr_t(_variant_t(valy))<< L"}"<< endl;
            hr = rs->MoveNext();
        }

        hr = hr;
    }
    CoUninitialize();

    return 0;
}


这篇关于如何在使用DAO的VC ++(MFC)访问中写入和读取多值字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 15:52