Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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),
              //val3 SearchString.Replace("\"","")

          };

  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);
Posted
Updated 16-May-20 22:13pm
v3
Comments

1 solution

Problem solved
solving problem by pass json from front end on search string on format
"'Text6='MFG'" it solved my issue
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900