Table name and table field on SqlParameter C#?

If you are worried about SQL injection, the SqlCommandBuilder class (and other DB specific versions of DbCommandBuilder) have a function called QuoteIdentifier that will escape your table name properly.

var builder = new SqlCommandBuilder();
string escTableName = builder.QuoteIdentifier(tableName);

Now you can used the escaped value when building your statement and not have to worry about injection- but you should still be using parameters for any values.

Leave a Comment