Do a custom query in script code

edited 10:52PM in FastReport .NET
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 10:52PM
    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

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.