Home > Language Reference > Database Functions > DbExecute

DbExecute

The DbExecute function performs the specified SQL statement on the current recordset.

Usage

Used to delete, insert or update records.

Syntax

ret = DbExecute("<SQL_command>")

Parameters

<SQL_command>, string, a valid SQL statement. If the <SQL_command> is not accepted, verify it is a valid one using Msgbox function to display it first before using it in DbExecute.

Return value

ret, optional numeric return value. If the function successfully executes the query, the return value is 0. If the function fails, the return value is a nonzero value (see Error Codes for Database Functions).

See also

DbBof
DbClose
DbConnect
DbDisconnect
DbEof
DbGetFieldNumeric
DbGetFieldString
DbMove
DbMoveFirst
DbMoveLast
DbMoveNext
DbMovePrev
DbRecordCount
DbSelect

Examples

'The example uses a data source name called DBTest which contains those records in a table called DATA:
' a,1, 1.23, 02/01/2011
' b,2, 2.34, 03/02/2012
' c,3, 3.45, 04/12/2009
DbConnect("DSN=DBTest") ' connection to ODBC database called DBTest
DbExecute("UPDATE DATA SET champ2=champ2+100") ' updates the table DATA
DbDisconnect()


DbConnect("DSN=DBTest") ' connection to ODBC database called DBTest
DbExecute("DELETE from DATA WHERE Champ1>50") ' deletes selected records in the table DATA
DbDisconnect()


DbConnect("DSN=DBTest") ' connection to ODBC database called DBTest
DbExecute("INSERT into DATA (champ2) VALUES ('4000')") ' inserts in champ2 of the DATA table a new value
DbDisconnect()