Update SQL data but the data contains ' so I get errors

淺唱寂寞╮ 提交于 2020-04-17 20:38:51

问题


I'm trying to update SQL data but it contains ' so I get errors.

The SQL statement looks like this:

UPDATE SystemConfiguration
SET    HeaderScript = '<script> (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],' 
WHERE  ID = 1

I tried to replace the quote with " but I get error. I also tried without quote I get error as well.

Any suggestions.


回答1:


You need to double the single quotes to escape them:

UPDATE SystemConfiguration
SET    HeaderScript = '<script> (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({''gtm.start'': new Date().getTime(),event:''gtm.js''});var f=d.getElementsByTagName(s)[0],' 
WHERE  ID = 1


来源:https://stackoverflow.com/questions/60892059/update-sql-data-but-the-data-contains-so-i-get-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!