set report sql select command

i am using fastreport : (FastReport.OpenSource.Data.SQLite)
when i am try to change select command through :

TableDataSource table = report.GetDataSource("Table") as TableDataSource;
table.SelectCommand = "Select * from Customers"; // CustCode,CustName,CustAddress,CTel,Job,Remarks,....
MemoryStream stream = new MemoryStream();
try
{

Config.WebMode = true;
using (report)
{
report.ConvertNulls = true;
report.Prepare();
HTMLExport export = new HTMLExport();
export.Layers = true;
export.EmbedPictures = true;
export.Export(report, stream);
stream.Flush();
}
mime = "text/html";// + query.Format; // Override mime for html
return File(stream.ToArray(), mime, MvarReportFileName);
}
catch (Exception ex)
{
//{System.Exception: Text30: Error in expression: Table.CustAddress at FastReport.TextObjectBase.CalcAndFormatExpression(String expression, Int32 expressionIndex) at FastReport.TextObject.GetData() ...
return File(stream.ToArray(), mime);
}
i got the following error When Field CustAddress is null :
System.Exception: Text30: Error in expression: Table.CustAddress at FastReport.TextObjectBase.CalcAndFormatExpression(String expression, Int32 expressionIndex) at FastReport.TextObject.GetData() ...

if i change the select statement to "select CustCode,CustName,ifnull(CustAddress,'') as CustAddress erorr disappeared
the error comes when certain field has null value , even if i set report.ConvertNulls=true
do you have easy solution other than ifnull function to set the null database field to space ???

Comments

  • Hello!

    After changing `table.SelectCommand` on an already loaded template, the table column schema is not re-read (the column name or type has changed, or the query has changed, but `InitSchema()`/`RefreshTable()` have not been called).

    In FastReport.OpenSource 2019–2020, DBNull sometimes caused an error in CalcAndFormatExpression when mixing dynamic SQLite types if CustAddress was not correctly typed as System.String.

    Try the following steps:

    var table = report.GetDataSource(“Table”) as TableDataSource;
    table.SelectCommand = “SELECT * FROM Customers”;
    table.InitSchema(); // update column metadata for the new SELECT
    report.ConvertNulls = true;
    report.Prepare();
    

    And update FastReport.OpenSource and FastReport.OpenSource.Data.SQLite to the latest version

This discussion has been closed.