![](/img/trans.png)
[英]Sending an empty array from ajax gave a null parameter in ASP.NET MVC action
[英]ASP (not .NET): sending null as parameter to stored procedure in query string?
我在 ASP 页面上有以下代码:
<%
QueryToJSON(conn, "execute WebGetEmployeesPlanned'"
+Request.QueryString("customercode")+"',
'"+Request.QueryString("lang")+"',
'"+Request.QueryString("date")+"'").flush
%>
除了一些包含之外,此页面上没有其他代码,因为我使用 ajax 从另一个页面调用此页面,使用 $.getJSON()
问题是我不知道如何将 NULL 作为参数之一发送给 SP。
有时 Request.QueryString("customercode") 将为空。 我需要知道如何将它放在上面的代码中,以使 SP 将此参数视为 NULL。
我可以访问 SP 代码,因此我可以更改该侧的某些内容以将空字符串转换为 null。
提前致谢。
你在正确的轨道上。 查询字符串参数只是字符串。 因此,您必须为 NULL 选择一个字符串代表,它不会与您将发送的任何实际字符串值冲突。 您可以使用空字符串、“null”或“Thomas 的特殊 null 标志”; 没关系。 查询字符串参数中没有 NULL 的“官方”表示。
更新:不,我不认为存储过程是处理这个翻译的地方。 原因是您将查询字符串参数中 null 的字符串表示形式转换为“真实” null 的事实是您必须做的事情,因为您可以放入查询字符串参数的限制。 在存储过程中进行这种转换会使该过程在某种程度上“意识到”查询字符串,这感觉不对。 相反,我会在 aspx 标记中执行此操作,该标记应该是 Web 感知的。 这是一个源示例(未经测试,因此请修复我的语法错误,或者更好的是,更改为 string.Format() 或参数化查询...
改变:
QueryToJSON(conn, "execute WebGetEmployeesPlanned'"
+Request.QueryString("customercode")+"',
'"+Request.QueryString("lang")+"',
'"+Request.QueryString("date")+"'").flush
至:
QueryToJSON(conn, "execute WebGetEmployeesPlanned "
+ (string.IsNullOrEmpty(Request.QueryString("customercode")) ?
"null, '"
:
"'" + Request.QueryString("customercode") + "','")
+Request.QueryString("customercode")+"',
'"+Request.QueryString("lang")+"',
'"+Request.QueryString("date")+"'").flush
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.