我有一个像这样的存储过程
ALTER PROCEDURE dbo.sp_CheckGlobalizationResourceValue
(
@ResourceObject NVARCHAR(255),
@ResourceName NVARCHAR(128)
)
AS
select count(*) from vpglobalizationresources
where ResourceObject = @ResourceObject and
ResourceName like '%' + @ResourceName + '%'
我正在使用Linq to SQL类。我从.cs文件发送ResourceObject和ResourceName,如上所示。它的returnValue总是0为什么?存储过程或cs类有什么问题吗?我在数据库中运行此查询,它在那里工作正常。
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");
}
}
答案 0 :(得分:0)
问题可能出在您的存储过程中。我想你需要在ResourceObject过滤中使用like
语句
select count(*) from vpglobalizationresources
where ResourceObject like @ResourceObject and
ResourceName like '%' + @ResourceName + '%'
@ResourceObject中的sleshes也可能存在问题。只是尝试使用实际的参数值执行Select
并检查是否有一些数据返回