将数据传递给 searchstring 参数不起作用

Passing data to searchstring parameter not working

我在将值作为 'Text6=''locations''' 传递给 C# 中的参数搜索字符串时遇到问题。

它给我错误:

An expression of non-boolean type specified in a context where a condition is expected, near 'and'.

问题出在下面的函数中,当将值 'Text6=''locations''' 传递给 @searchstring 时,它给出了如图所示的错误。

{ 
"startdate": "2020-05-03T22:00:00Z", 
"enddate": "2020-05-11T22:00:00Z", 
"searchstring": "'Text6=''MFG'''", 
"reportID": "2028" 
} 

public DataTable GetReportDetailsSearch(string ReportID, string FromDate, string ToDate, string SearchString)
      {

          List<SqlParameter> param = new List<SqlParameter>()
          {
              new SqlParameter("@ReportID", ReportID),
              new SqlParameter("@ReportDateFrom", FromDate),
              new SqlParameter("@ReportDateTo", ToDate),
              new SqlParameter("@SearchString",SearchString),


          };

  DataTable ReportDetailsSearch = SQLDAL.ReturnDataTableByProcedure("sp_ReportDetailsGetALL", param);
          return ReportDetailsSearch;
      }

网络APIasp.net核心2.2

[Route("ReportDetailsSearch")]
       [HttpPost]
       public IActionResult GetSearchedData([FromBody] dynamic DataObjectSearch)
       {

           try
           {
               string ReportId = DataObjectSearch.reportID;
               string FromDate = DataObjectSearch.startdate;
               string StartDate = FromDate.Substring(0, 10);
               string todate = DataObjectSearch.enddate;
               string EndDate = todate.Substring(0, 10);
               string Searchdata = DataObjectSearch.searchstring;

               var PostSearch = _reportservice.GetReportDetailsSearch(ReportId, StartDate, EndDate, Searchdata);

               return Ok(PostSearch);


       }

但是在 SQL 服务器上运行成功:

 exec [dbo].[sp_ReportDetailsGetALL] "2028","2020-05-03","2020-05-11", 'Text6=''locations'''

程序如下:

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)

我的问题通过将数据从前端传递到 Web API 解决了,如下所示:

searchstring = "Text6='MFG'"