Database Functions
These functions execute SQL against the DGS data source configured for the scripting context.
ExecuteScalar
ExecuteScalar(SQL)
Executes a SQL query and returns the value of the first column of the first row. Useful for single-value queries such as COUNT, SUM, or MAX.
| Parameter | Description |
|---|---|
SQL |
A SQL SELECT statement |
Returns: Object (the scalar result, or Nothing if no rows)
Examples:
ExecuteScalar("SELECT COUNT(*) FROM Orders WHERE Status = 'Open'")
ExecuteScalar("SELECT MAX(Price) FROM Products")
ExecuteScalar("SELECT Name FROM Customers WHERE ID = " & CustomerID)
GetTable
GetTable(SQL, [ConnectionString])
Executes a SQL query and returns the full result set as a DataTable.
| Parameter | Description |
|---|---|
SQL |
A SQL SELECT statement |
ConnectionString |
(optional) Connection string to use. If omitted, uses the default DGS data source. |
Returns: DataTable
The returned DataTable can be used with GetRowColumn to access individual cells, or passed to aggregate functions.
Examples:
Dim tbl = GetTable("SELECT * FROM Products WHERE Active = 1")
Dim count = GetRowColumn(tbl, 0, "ProductName")
Dim tbl2 = GetTable("SELECT * FROM RemoteDB", "Server=srv;Database=db;...")