I am executing an SQL query (system.data.SQLite) like so:
var color = "red";
var command = new SQLiteCommand("SELECT something FROM tabletop WHERE color = '" + color + "'", Connection);
var reader = command.ExecuteReader();
The color variable is a text supplied by the user. How can I escape this text to prevent SQL injection? Or is this bad practice and I should execute the query in some entirely different "protected" way?
You do it with prepared statements:
You should use parameterized queries:
You can also pass an array of
SQLiteParameter
s into thecommand.Parameters
collection like so: