How do I convert a string into safe SQL String?

前端 未结 2 809

I\'m generating some sql insert statements from a bunch of text files.

These text files are generally user input data. I would like to sanitize this data so that it\

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 14:13

    Don't sanitize your strings. Use parameterized queries instead, as they handle all sanitization.

    You don't specify which database you are using, so I assume it is MS SQL Server. Microsoft has an article on the official ASP.net website about this. Also see MSDN for SqlCommand.Parameters and the AddWithValue method.

提交回复
热议问题