Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
ADO and Visual C++
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00861536
Message ID:
00862031
Vues:
18
>Does anybody know how to access dbf (VFP 6) files in Visual C++ 6 using ADO? Will you please give me an example.
// ADOsample.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#import "D:\Program Files\Common Files\System\ADO\msado21.tlb" \
	no_namespace rename("EOF", "EndOfFile")

int main(int argc, char* argv[])
{
	_RecordsetPtr	rs;
	_ConnectionPtr	conn;

	CoInitialize(0);

	try
	{
		HRESULT hr = conn.CreateInstance( __uuidof(Connection) );
		if (FAILED(hr)) _com_issue_error(hr);

		conn->Open( L"Provider=VFPOLEDB.1;"
			L"Data Source=D:\\Program Files\\Microsoft Visual FoxPro 7\\Samples\\Data\\testdata.dbc;Collating Sequence=MACHINE",
			"", "", -1 );

		rs = conn->Execute( L"Select company, contact from customer", &vtMissing, adOptionUnspecified);
		
		while( !rs->EndOfFile )
		{
			printf("%s %s\n", (char*)_bstr_t(rs->Fields->Item[0L]->Value),
							  (char*)_bstr_t(rs->Fields->Item[1L]->Value));
			rs->MoveNext();
		}

		rs->Close();
		conn->Close();
	}
	catch( _com_error &e)
	{
		_bstr_t bstrSource(e.Source());
		_bstr_t bs =  _bstr_t("Error: ") + _bstr_t(e.Error()) + _bstr_t("\nMsg: ") 
			+ _bstr_t(e.ErrorMessage()) + _bstr_t("\nDescription: ") 
			+ _bstr_t(e.Description());
		
		MessageBox(0, bs, bstrSource, MB_OK);
	}	  

	CoUninitialize();
	return 0;
}
You could also check AdoClass from www.codeproject.com, which can simplify the code writing.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform