Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ADO and Visual C++
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00861536
Message ID:
00862031
Views:
19
>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.
Previous
Reply
Map
View

Click here to load this message in the networking platform