TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ahmed elbarbary
NA
1.6k
281.4k
search string not work if i pass it arrounded single quotes
May 15 2020 7:30 PM
When execute web api search string added to it double quotes why and how to solve issue ?
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 from sql succes as below
exec [dbo].[sp_ReportDetailsGetALL]
"2028"
,
"2020-05-03"
,
"2020-05-11"
,
'Text6='
'locations'
''
exactly issue on the following line
'Text6='
'locations'
''
not work if as below
"'Text6=''MFG'''"
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 getreportdetail 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)
{
try
{
string Searchdata = DataObjectSearch.searchstring;
var
PostSearch = _reportservice.GetReportDetailsSearch(ReportId, StartDate, EndDate, Searchdata);
return
Ok(PostSearch);
}
Reply
Answers (
1
)
Error on Importing Excel to SQL database table
Datetime issue after Deployed in iis in Cloud server?