ADO.net SqlParameter在单词之间使用加号+号。

huangapple go评论77阅读模式
英文:

ADO.net SqlParameter using a + sign between words

问题

I am using ADO.net and using SqlParameter passing into a stored procedure a group of words that sometimes may have a + between then. Up until the plus sign the search is working fine but once I add it I am getting no results. Do I need to change anything in the c# code I am run the sp fine with the plus sign.

c# code

SqlParameter[] parms = new SqlParameter[] {
    new SqlParameter("@Title", SqlDbType.VarChar)
};
parms[0].Value = Title;

SQL SP

create PROCEDURE [usp_Select_Title] -
    -- Add the parameters for the stored procedure here  
    @Title nvarchar(512) = null
WHERE (dcc.Title like '%' + @Title + '%')
英文:

I am using ADO.net and using SqlParameter passing into a stored procedure a group of words that sometimes may have a + between then. Up until the plus sign the search is working fine but once I add it I am getting no results. Do I need to change anything in the c# code I am run the sp fine with the plus sign.

c# code

SqlParameter[] parms = new SqlParameter[] {
    new SqlParameter("@Title", SqlDbType.VarChar)
};
parms[0].Value =Title;

SQL SP

create PROCEDURE [usp_Select_Title] -
	-- Add the parameters for the stored procedure here  
@Title nvarchar(512) = null




WHERE (dcc.Title like '%'+ @Title +'%') 

答案1

得分: 2

根据评论中的讨论,该值是通过URL中的查询字符串传递的。在这种情况下,+号在查询字符串中具有语义意义,用于表示空格。

因此,解决此问题的方法是在URL中将+号编码为%2B,然后在C#中解码回+号。

参考:

英文:

As per the discussion in comment, the value was passed to via query string in URL. In this the case the + sign has a semantic meaning in the query string which is used to represent a space.

So, the solution for this is to encode the + sign with %2B in URL and decode back to + in C#.

References:

huangapple
  • 本文由 发表于 2023年7月20日 21:36:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76730469.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定