The apostrophe (') processing in the report parameter exceeded expectations

edited 11:00AM in FastReport .NET
Hi all,

The data source of the following SQL query is defined in the FastReport.net report, where the expression of the @NAMES variable refers to the report parameters [PNames].
SELECT * from Table1 where name in (@NAMES)

Report parameters [PNames] Assign values in C # code:
Rpt. SetParameterValue ("PNames", "'A','B','C'");

Obviously, I expect the SQL query statement as follows:
SELECT * from Table1 where name in ('A','B','C')

But debugging found that FastReport put me in the string all the single quotes plus a layer, the final execution of the SQL statement into the following appearance:
SELECT * from Table1 where name in (''A'',''B'',''C'')

The result is obviously totally wrong!

I tried to pass only one value without single quotation marks, and ultimately because Fr added a single quote, the SQL statement was correctly spliced:
Rpt. SetParameterValue ("PNames", "a");

Try a variety of combinations, as long as the string contains single quotes, FR will eventually turn a single quotation mark into two, for a long time, who knows exactly how to write it?

Thanks

Comments

  • edited 11:00AM
    Please help me, thank you very much!
  • edited 11:00AM
    try to construct parameterized query from report script
        private void _StartReport(object sender, EventArgs e)
        {
          string parameter = Report.GetParameterValue("MyParameter").ToString();
          TableDataSource tds = Report.GetDataSource("YourDataSourceName") as TableDataSource;
          tds.SelectCommand = "SELECT * from Table1 where name in (" + parameter + ");";
        }
    
  • edited 11:00AM
    ipong wrote: »
    try to construct parameterized query from report script
        private void _StartReport(object sender, EventArgs e)
        {
          string parameter = Report.GetParameterValue("MyParameter").ToString();
          TableDataSource tds = Report.GetDataSource("YourDataSourceName") as TableDataSource;
          tds.SelectCommand = "SELECT * from Table1 where name in (" + parameter + ");";
        }
    

    Great, it's OK, Thank you very much for your time. >>>

Leave a Comment