📘
TimeLine E3
  • TimeLine E3 Documentation
  • Framework
    • Introduction
    • DataSet Definition
    • Window Handling Object
      • Input/Output arguments
      • Open
      • BindDataControls
      • Item Changes
      • Item Search
      • MenuItemClicked
      • Print
      • ModuleOpened (BlueArrow)
      • BlueArrowArguments
      • New Row
      • Delete Row
      • Save
      • Transactions
      • Locking [deprecated]
      • Locking (new)
      • Resizing a response window
      • ParaPanel
      • Adding DMS Tab to a Module
    • BusinessObject
    • Controls
      • BindingFormat
      • LookupGrid and SearchDef
      • ComboBox
      • RadioButton
      • Multiline Textbox
      • xTextBoxSearch
      • xFileBrowse [v16+]
      • DxDispoColumn
      • DxProgressColumn
      • DxTemplateColumn
      • Change control caption programmatically
      • TabControl
      • Navigation
      • Enable controls programmatically
      • Enable a MenuItem programmatically
      • Filter search values
      • Jumping to another module
      • Messages, Notifications, Log, Exceptions, Translation
      • LoggerSink [deprecated]
      • Log
      • OpenFile, FolderBrowsing and SaveFile
      • Execute Actions while displaying an Hourglass
      • Using Progress
      • Async methods with progress bar
      • Wizard
      • Customizing controls using xBehaviors
      • TLProperty.AllowInReadOnly [v16+]
    • DataSet Operations
    • Business-related functionality
      • Getting the next primary key
      • Hybrids
      • Enums
      • Get Current User
    • SQL
    • SQL (using named parameters)
    • Advanced SQL
    • Expression Binding
    • Server-side logic & customization [v16+]
      • Service Hoster
      • Starting / stopping hosted services
      • Changes to scheduled jobs!
      • Business Object Proxies
      • Business Object API
    • Colors in Expression Bindings [v15+]
    • Theming
      • Icons
  • TimeLine Developer (TLD)
    • Debugging in TLD
    • Targets
    • Custom Project Rework [v16+]
  • TimeLine-specific LL functions
  • Stunnel proxy
    • Pre-requisites
    • 1. Initial setup
    • 2. Generate the server/web certificates
    • 3.a. Generating client certificates using the CSR flow
    • 3.b. Generate client certificates from the server console
    • 4. Setting up the E3 client connection
    • 5. Setting up the browser certificates
  • Configuration
    • Configuring the WCF timeout
  • Troubleshooting the E3 Bridge
  • [Deprecated]
    • TimeLine WEB - deprecated in v16+
      • Prerequisites for running the WASM modules on the server
      • Prerequisites for developing WASM modules with TLD
      • Creating a small web module with TLD
      • Terminal Configuration
    • Customization Examples - deprecated in v16+
    • Codestore [deprecated]
    • Configuring the scheduled jobs timeout - deprecated in v16+
Powered by GitBook
On this page
  1. Framework

SQL (using named parameters)

We recommend using the following Anonymous Types / Dictionary approaches for passing SQL parameters instead of formatted strings. This approach is safer and no longer requires you to provide quotes for escaping string values.

Bellow you can see how using an anonymous type object to provide the parameter values. Note how the parameter values are provided in the SQL statement:

Sql.SelectRow(
    "SELECT lager_nr, bestand FROM bestand WHERE lager_nr = :lagerNr AND art_nr = :artNr",
    new { lagerNr = 123, artNr = "abc" });

For further simplification you can use variables instead of explicit values for each variable needed.

var lagerNr = 123;
var artNr = "abc";

Sql.SelectRow(
    "SELECT lager_nr, bestand FROM bestand WHERE lager_nr = :lagerNr AND art_nr = :artNr",
    new { lagerNr, artNr });

For large SQL statements that need to be concatenated in a loop you can use a dictionary instead. The code bellow generates multiple inserts and executes them in a single Sql.Execute call.

var sqlParams = new Dictionary<string, object>();

// generate multiple update statements
for (int i = 0; i < 5; i++)
{
		sqlParams[$"lagerNr{i}"] = 123;
		sqlParams[$"artNr{i}"] = "abc";
		
		sqlStatement += 
				$"INSERT INTO bestand (lager_nr, artNr) VALUES ( :lagerNr{i}, :artNr{i} );" 
				+ Environment.NewLine;
}

Sql.Execute(sqlStatement, sqlParams);
PreviousSQLNextAdvanced SQL

Last updated 3 years ago