Do a custom query in script code

Hello.

I'm new in FastReport. I come from Microsoft Access, and there I could do a subquery using actual database connection, like that:

string SQL = "SELECT name FROM customers WHERE ID = 23";
string Name = getValueFunction(SQL);

I don't find how do that in FastReports. I have necesary datasources in my report design for prepare my report, but sometimes, I need to query puntual data from another table.

Can I do this in FastReports?

Thanks.

Comments

  • edited 4:18PM
    Hello again.

    I found this solution trying this weekend, but I don't think it's the best solution.

    private string getValue(string DataSource, string SQL)
    {
    TableDataSource source = (TableDataSource)Report.GetDataSource(DataSource);
    DataConnectionBase connection = source.Connection;

    System.Data.DataTable table = new System.Data.DataTable(DataSource);
    CommandParameterCollection param = new CommandParameterCollection(null);

    connection.FillTableData(table, SQL, param);
    return table.Rows[0].ItemArray[0].ToString();
    }

    With this function I can do a query from my report using any table from my BD.

    Do you have a better solution?. Thanks!

Leave a Comment