SQL injection occurs when an application treats user input as part of an SQL command instead of as data. An attacker can then alter database operations or access, change, or destroy data. section 8.3.1 section 8.10
When a name becomes a command
In the “Little Bobby Tables” story, a malicious first name contains SQL intended to delete a student database. Poorly written software executes the input as a command rather than saving it as a name. section 8.7
Prevent this by using parameterized queries: give user input a data slot so the database treats even command-like text as a literal value. Avoid concatenating input into query strings, including for internal-facing applications. section 8.7.2
// SAFE: The database treats the input as a harmless string
string query = "SELECT * FROM Students WHERE Name = @Name";
command.Parameters.AddWithValue("@Name", userName);A parameterized student-name query demonstrates the safe pattern: the input is supplied separately from the SQL command. section 8.7.2











