Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL INSERT to MS Access Failing
Message
 
 
To
01/11/2011 07:11:19
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01527718
Message ID:
01527768
Views:
63
Unfortunately, OUTPUT clause is for SQL Server, not for Access. In Access there is no SCOPE_IDENTITY() or OUTPUT clause.

>Naomi, I have been unable to find any examples of proper syntax for using the OUTPUT clause from VFP with an Access database. I've tried the following code snippet with about a dozen different variations, bracketing table and field names, different order of clauses, and so forth. My results every time were an error message: "Connectivity error: {Microsoft][ODBC Microsoft Access Driver] Invalid SQL statement; expected 'DELETE', 'INSERT','PROCEDURE','SELECT', or 'UPDATE'."
>
>
>lcSourceFile = "C:\projects\\FRS\FRS5Data.accdb" 
>pnConnHandle = SQLSTRINGCONNECT("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + ; 
>   					  				  lcSourceFile) 
>TEXT TO lcSQLCommand NOSHOW 
>DECLARE @MyTable table( id INTEGER, myvalue varchar(10) );
>
>INSERT INTO [TblHousehold] (SYSTEMPROGRAMCD, PROGRAMCD,LSTUPDTDTTM) VALUES (?m.sysprogcd,?m.programcd,?m.lstupdtdttm) && values populated by SCATTER
>OUTPUT INSERTED.HouseholdSeqNbr, INSERTED.householdversionnbr INTO @myTable
>
>SELECT * FROM @myTable
>ENDTEXT
>
>lnResult = SQLEXEC(pnConnHandle,lcSQLCommand)
>
>IF lnResult <= 0
>	AERROR(laError)
>	MessageBox(laError[1,2])
>ENDIF 
>
>
>On the other hand, this works, so the basic concept is ok, just the OUTPUT syntax be foober.
>
>lcSourceFile = "C:\projects\FRS\FRS5Data.accdb" 
>pnConnHandle = SQLSTRINGCONNECT("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + ;
>   					  				  lcSourceFile)
>TEXT TO lcSQLCommand NOSHOW
>INSERT INTO [TblHousehold] (SYSTEMPROGRAMCD, PROGRAMCD,LSTUPDTDTTM) VALUES (?m.sysprogcd,?m.programcd,?m.lstupdtdttm)
>ENDTEXT
>
>lnResult = SQLEXEC(pnConnHandle,lcSQLCommand)
>
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform