I would like to know how to pass the table name and a table field name via SqlCommand on C#.
Tryied to do it the way it's done by setting the SqlCommand with the @ symbol but didn't work. Any ideas??
See Question&Answers more detail:osI would like to know how to pass the table name and a table field name via SqlCommand on C#.
Tryied to do it the way it's done by setting the SqlCommand with the @ symbol but didn't work. Any ideas??
See Question&Answers more detail:osIf 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.