DbCommand (Support only at CTLX)

 

The 'DbCommnad' function executes the query statement to database.

 

int @DbCommand(string dsn, string query_string);

 

Parameters

string dsn : Database connection string name.

string query_string : Query statement to execute.

 

Return Value

If execution is completed succesfully, it returns 1. But if error occurs, it returns -1.

 

Example

[Insert]

@sprintf(query,"INSERT INTO Table1 (Coulmn1,Column2,Column3) VALUES(%d, '%s', '%s')", $AI_0000, $ST_0000, $ST_0001);

@DbCommand("TestDsn", query);

Description : It inserts the AI_0000, ST_0000 and ST_0001 tag data to Table1 of TestDsn database.

At this time, the data is entered to fit the field type of Table. (In case of string, attach the ' at both sides of character)

 

[Delete]

@sprintf(query,"DELETE FROM Table1 WHERE Column2 = '%s'",$ST_0000);

@DbCommand("TestDsn", query);

Description : It deletes the rows where value is same with ST_0000 string tag, at TestDsn database.

 

[Update]

@sprintf(query,"UPDATE Table1 SET Column2='CDE' WHERE ID=100");

@DbCommand("TestDsn", query);

Description : It changes the Column2 column value which ID column value is 100 at Table1 of TestDsn database, as CDE.

For example as below table, Acd value is changed as CDE.

 

ID

Column1

Column2

Column3

1

290256

Edk765

12344df

2

234

Ad3edk

6345t

3

578

Edk4545

Fdadf5356

100

12421

Acd

62355

<Table 1> Table before executing the Update statement

 

ID

Column1

Column2

Column3

1

290256

Edk765

12344df

2

234

Ad3edk

6345t

3

578

Edk4545

Fdadf5356

100

12421

CDE

62355

<Table 2> Table after executing the Update statement

 

Relate items)

@DbDsOpen()

@DbDsClose()

@DbDsGetRowData()

@DbDsGetRowCount()

 

Download the Example

Download the Applied Example(RECIPE)

You can refer to the example at ProjectManager program by selecting "File | Restore" menu.