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. I send ResourceObject and ResourceName from .cs file which is shown above. And it's returnValue is always 0 why? Is there something wrong in stored procedure or cs class? 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
select count(*) from vpglobalizationresources
where ResourceObject like @ResourceObject and
ResourceName like '%' + @ResourceName + '%'
It's also may be problem with sleshes in @ResourceObject. Just try to execute Select
with real values of parameters and check is there is some data returns back or not
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.