I work on web api asp.net core 2.2 I face this error
An expression of non-boolean type specified in a context where a condition is expected, near 'and'.
procedure work success on sql server as below
exec [dbo].[sp_ReportDetailsGetALL] "2028","2020-05-03","2020-05-11", 'Text6=''locations'''
exactly issue on the following line
'Text6=''locations'''
on web API i think it add double quotes on start and end so that it not work
json i passed to web API as following :
{
"startdate": "2020-05-03T22:00:00Z",
"enddate": "2020-05-11T22:00:00Z",
"searchstring": "'Text6=''MFG'''",
"reportID": "2028"
}
procedure as following :
declare @ColumnName Nvarchar(max) = (SELECT 'select ' + STUFF((SELECT ',' + 'Text'+CONVERT(varchar(20),ReportHeaderIndex) + ' '+ '['+ReportHeader +']'
FROM ReportHeaders where ReportID=@ReportID order by ReportHeaderIndex
FOR XML PATH('')) ,1,1,'') + ' , convert(nvarchar(20),[ReportDate]) ReportDate From ReportDetails R where ReportDate >= ''' +@ReportDateFrom+''' and ReportDate <= '''+ @ReportDateTo +''' and R.ReportID =' + @ReportID + ' and '+@SearchString+' and IsHistory=0 order by reportdate desc ' + @SortingColumns AS Txt )
exec (@ColumnName)
What I have tried:
public DataTable GetReportDetailsSearch(string ReportID, string FromDate, string ToDate, string SearchString)
{
List<SqlParameter> param = new List<SqlParameter>()
{
new SqlParameter("@SearchString",SearchString),
};
DataTable ReportDetailsSearch = SQLDAL.ReturnDataTableByProcedure("sp_ReportDetailsGetALL", param);
return ReportDetailsSearch;
}
[Route("ReportDetailsSearch")]
[HttpPost]
public IActionResult GetSearchedData([FromBody] dynamic DataObjectSearch)
{
string Searchdata = DataObjectSearch.searchstring;
var PostSearch = _reportservice.GetReportDetailsSearch(ReportId, StartDate, EndDate, Searchdata);
return Ok(PostSearch);