简体   繁体   English

在存储过程中使用LIKE命令

[英]using LIKE command in Stored Procedure

I have a stored procedure like this 我有一个这样的存储过程

ALTER PROCEDURE dbo.sp_CheckGlobalizationResourceValue
 (
   @ResourceObject NVARCHAR(255),
   @ResourceName NVARCHAR(128)
    )

AS

select count(*) from vpglobalizationresources
      where ResourceObject = @ResourceObject and 
ResourceName like '%' + @ResourceName + '%' 

And I'm using Linq to SQL classes. 我正在使用Linq to SQL类。 I send ResourceObject and ResourceName from .cs file which is shown above. 我从上面显示的.cs文件发送ResourceObject和ResourceName。 And it's returnValue is always 0 why? 而且它的returnValue总是为0,为什么呢? Is there something wrong in stored procedure or cs class? 存储过程或CS类有问题吗? I ran this query in database and it works fine there. 我在数据库中运行了此查询,并且在该数据库中运行良好。

public static bool CheckGlobalizationResourceValue(string resourceObject, string resourceName)
    {
        try
        {
            using (var dataContext = new ResourceDBDataContext())
            {
                resourceObject = resourceObject.Replace(ConfigurationHelper.MainDirectory + "\\", "");
                resourceObject = resourceObject.Replace("\\", "/");
                //resourceName = string.Format("'%{0}%'", resourceName);

                var result = dataContext.sp_CheckGlobalizationResourceValue(resourceObject, resourceName);
                if ((int)result.ReturnValue == 0)
                {
                    return false;
                }
                else
                {
                    return true;
                }
                //return (int)result.ReturnValue != 0;
            }
        }
        catch (Exception exception)
        {
            throw new Exception("An error occured when retrieving data from database");
        }
    }

The problem may be in your stored procedure. 问题可能出在您的存储过程中。 I guess you need to use like statement in ResourceObject filtration 我猜你需要在ResourceObject过滤中使用like语句

select count(*) from vpglobalizationresources
      where ResourceObject like @ResourceObject and 
ResourceName like '%' + @ResourceName + '%' 

It's also may be problem with sleshes in @ResourceObject. @ResourceObject中的sleshes也可能有问题。 Just try to execute Select with real values of parameters and check is there is some data returns back or not 只需尝试使用参数的真实值执行Select并检查是否有一些数据返回

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM