liveBook · Manning

SQL parameter

As explained in Building Web APIs with ASP.NET Core

An SQL parameter is a typed placeholder whose value is supplied separately from an SQL statement's command text.

An SQL parameter is a typed placeholder whose value is supplied separately from an SQL statement’s command text. This separation helps prevent SQL injection when values are dynamic. section 4.3.1

Use parameters when constructing SQL with external or changing values:

  • Avoid inserting variables directly into SQL strings, because unescaped content can alter the command. section 4.3.1
  • Declare a parameter with a database type, then assign its value separately. section 4.3.1
  • Let EF Core generate parameterized SQL when its configured data-access API is used. section 4.3.1
SqlDataAdapter myCommand = new SqlDataAdapter(  
"UPDATE users SET notes = @notes", conn);  
SQLParameter parm = 
   myCommand.SelectCommand.Parameters.Add("@notes",
       SqlDbType.VarChar, 11);  
Parm.Value = notes;

This listing shows a typed @notes placeholder receiving its value separately from the UPDATE command. section 4.3.1

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Defines parameters and demonstrates declaration and assignment, but leaves database-provider internals to the execution system.
Examples
Shows an UPDATE statement that assigns a user note through a typed @notes parameter.
What it assumes
Assumes basic SQL and C# familiarity while illustrating parameter setup explicitly.
What you can do after
Apply parameters through provider APIs or let EF Core generate safer SQL from data-access code.
How it connects
Connects SQL parameters with SQL injection, dynamic SQL, stored procedures, ORM, and EF Core.

Also explained in

Compare how 2 books explain SQL parameter →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.