Escaping values in SQL queries (C# with SQL connector)

前端 未结 5 1827
囚心锁ツ
囚心锁ツ 2020-12-11 16:39

I know I can use the parameters, but what is the right way to escape string sequences? The query could be like this:

\"INSERT INTO records (ReferenceID,Name,         


        
5条回答
  •  臣服心动
    2020-12-11 17:20

    I think the only thing you need to do is value = value.Replace("'", "''")

    Of course you shouldn't do this, but you know that.

    Edit: Apparantly this is all wrong for MySQL. It should work for PostgreSQL, MS SQL and Oracle, though.

提交回复
热议问题