You need to use prepared statements. The way they are processed is that you write your request and put placeholders for the values ββyou want to use. Here is an example:
SELECT * FROM table WHERE column1 = @word
Then you need to go through the preparation phase, in which the SQL engine knows that it will need to bind parameters to the query. Then you can execute the request. The SQL engine needs to know when and how to interpret the parameters that you associate with your query.
Here is the code for this:
SqlCommand command = new SqlCommand(null, rConn); // Create and prepare an SQL statement. command.CommandText = "SELECT * FROM table WHERE column1 = @word"; command.Parameters.Add ("@word", word); command.Prepare(); command.ExecuteNonQuery();
source share