Execute SQL - < odbc_exec_sql >() ... [Pro]
ODBC Execute SQL |
||||||||||||||||||||||||||||||||||||||||||||||||
This command executes an SQL command on a database previosly open using the "ODBC OPEN" command. |
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
Example (Macro Steps):
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Example (Plain Text):
<#> This example shows how to execute an SQL command on opened Microsoft Access database
<cmds>
<#> Show a form that lets a user to select the database file
<form_item>("f1","Microsoft Access database:","EDIT_FILE","*.accdb","vDbFile",1)
<form_show>("f1","Select Microsoft Access database to open","",0,500,0,,,1,1)
<if>("%_vCanceled%==1")
<#> User canceled the selection form, no database file is selected
<exitmacro>
<endif>
<if_file>("%vDbFile%","NOTEXIST","")
<#> User entered a file that does not exist
<msg>(-100,-100,"The file '%vDbFile%' was not found.","",1,0,2,0)
<exitmacro>
<endif>
<#> Build the Microsoft Access connection string
<varset>("vConnectionString=Driver={MICROSOFT ACCESS DRIVER (*.mdb, *.accdb)}; Dbq=%vDbFile%;","")
<#> Open the database
<odbc_open>("%vConnectionString%",vDbOpen)
<if>("%vDbOpen%!=0")
<#> Set John's age to 33
<odbc_exec_sql>(%vDbOpen%,"UPDATE TestTable1 SET AGE=33 WHERE FRIEND='John'")
<#> Close the database
<odbc_close>(%vDbOpen%)
<endif>