Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Working with ODBC..
Message
De
27/04/2009 03:42:54
 
 
À
27/04/2009 03:30:08
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Divers
Thread ID:
01396459
Message ID:
01396461
Vues:
108
>I need to connect to an MS Access table. I read that I need to make use of the VFP ODBC driver to do this

Yes, you can use (the Access) ODBC (or OleDB) drivers.

> but I don't know how.
>If I do this, is it standard that I connect to this MS Access table then save the data on my own DBF file? Or can I work already with this Access table?
>

You can do both, either retrieve data by doing a "Select ... From ..." into a VFP cursor (and from there perhaps Insert Into yourPersistentVfpTable).

Or the other way around, "Insert Into ... theAccessTable ...", "Update theAccesstable ...", "Delete From theAccesstable ..."


hth
-Stefan
Set Step On
LOCAL llOK, lcErrorMessage
llOK = .T.
lcErrorMessage = ""

LOCAL lcMDB
IF m.llOK
	lcMDB = GETFILE('mdb')
	llOK = FILE(m.lcMDB,1)
	lcErrorMessage = ""
ENDIF

LOCAL lcConnectionString, h
IF m.llOK
	lcConnectionString = ;
		"DRIVER=Microsoft Access Driver (*.mdb);" + ;
		"DBQ=" + JUSTFNAME(m.lcMDB) + ";" + ;
		"DefaultDir=" + JUSTPATH(m.lcMDB) + ";" + ;
		"DriverId=25;FIL=MSAccess;MaxBufferSize=2048;PageTimeout=5"
	h = SQLSTRINGCONNECT(m.lcConnectionString)
	llOK = ( h > 0 )
	IF !m.llOK
		lcErrorMessage = GetLastError()
	ENDIF
ENDIF

* Get all available Access Tables if you want
LOCAL n
*!*	IF m.llOK
*!*		n = SQLTABLES(h,'','temp')
*!*		llOK = ( n > 0 )
*!*		IF !m.llOK
*!*			lcErrorMessage = GetLastError()
*!*		ENDIF
*!*	ENDIF
*!*	IF m.llOK
*!*		BROWSE
*!*	ENDIF

LOCAL lcTable
IF m.llOK
	lcTable = 'testTable' && whatever your specs say
	n = SQLEXEC(h,[Select * From ] + m.lcTable,'temp')
	llOK = ( n > 0 )
	IF !m.llOK
		lcErrorMessage = GetLastError()
	ENDIF
ENDIF
IF m.llOK
	BROWSE
ENDIF

LOCAL p1
IF m.llOK
	&& this fails
	n = SQLEXEC(h,[Insert Into ] + m.lcTable + [ (lTest) Values (.T.)])
	llOK = ( n > 0 )
	IF !m.llOK
		lcErrorMessage = GetLastError()
	ENDIF

	&& backend syntax works
	n = SQLEXEC(h,[Insert Into ] + m.lcTable + [ (lTest) Values (true)])
	llOK = ( n > 0 )
	IF !m.llOK
		lcErrorMessage = GetLastError()
	ENDIF

	&& ODBC mapping is easier
	p1 = .T.
	n = SQLEXEC(h,[Insert Into ] + m.lcTable + [ (lTest) Values (?p1)])
	llOK = ( n > 0 )
	IF !m.llOK
		lcErrorMessage = GetLastError()
	ENDIF
ENDIF

TRY
	SQLDISCONNECT(h)
CATCH
ENDTRY
IF !m.llOK AND !EMPTY(m.lcErrorMessage)
	MESSAGEBOX(m.lcErrorMessage,48)
ENDIF

RETURN


FUNCTION GetLastError()
	LOCAL lcMessage, laError[1]
	lcMessage = ""
	AERROR(laError)
	IF TYPE('laError[2]') = 'C'
		lcMessage = laError[2]
	ENDIF

	RETURN m.lcMessage
ENDFUNC
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform