使用.ExecuteSqlCommand如果参数包含单引号,我会收到以下错误:
在执行用户定义的例程或聚合\“Insert_Log_Error \”期间发生.NET Framework错误:\ r \ nSystem.Data.SqlClient.SqlException:'s'附近的语法不正确。
在's'之前,参数中有一个引号。
require 'date'
DateTime.rfc3339('2015-05-27T07:39:59Z')
#=> #<DateTime: 2015-05-27T07:39:59+00:00 ((2457170j,27599s,0n),+0s,2299161j)>
DateTime.rfc3339('2015-05-27T07:39:59Z').to_time
#=> 2015-05-27 09:39:59 +0200
DateTime.rfc3339('2015-05-27T07:39:59Z').to_time.to_i
#=> 1432712399
为了使它工作,我必须为每个字符串参数添加.Replace(“'”,“''”),因为它可以包含单引号,这远非理想。