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:
For further simplification you can use variables instead of explicit values for each variable needed.
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.
Last updated