passing sql to the report

Hi,

I designed the report, datasource is: Datasource->Connection->Table,Datasource->Connection->Table1, Datasource->Connection->Table2.

I cant pass the parameter, because selected command is a openquery from MSSQL to Oracle linked server (And by default you can't pass parameter in openquery.

So I'd like to change 3 sql tables directly from c# application


I don't want to create new data sources form c#, only change SQL command of existing one.


This is part of the code:

string appPath = System.Windows.Forms.Application.StartupPath;

string pathtoreport = appPath + "\\rep.frx";

 Report rp = new Report();          

  rp.Load(pathtoreport);

  TableDataSource t = rp.GetDataSource("Connection") as TableDataSource;

            t.SelectCommand = "select * from openquery(LinkedServer,'

select est.t$pdno, est.t$opno, est.t$pono, est.t$sitm , it.t$dsca, est.t$revi, est.t$cwar, est.t$bfls, op.t$cwoc, op.t$tano, op.t$rsdt,est.t$ques ,

case when it.t$seri = 1 then ''Yes'' else '' '' end as t$seri

, it.t$csig

from erpln6c.tticst001215 est

inner join erpln6c.ttcibd001215 it on it.t$item = est.t$sitm

inner join erpln6c.ttisfc010215 op on (op.t$pdno = est.t$pdno and op.t$opno = est.t$opno)

where est.t$pdno =''XXXXXXX''

order by est.t$opno, est.t$pono

')";


But this doesn't work.... my favorite error: object reference not set to an instance of an object.


What I'm doing wrong ?

Comments

  • Hello!

    Here is the correct code for updating the SelectCommand on three tables before calling Prepare()

    foreach (var dsName in new[] { “Table”, ‘Table1’, “Table2” })
    {
    var tds = rp.GetDataSource(dsName) as FastReport.Data.TableDataSource;
    if (tds != null)
    {
    tds.SelectCommand = $“SELECT * FROM OPENQUERY(ORACLE_SRV, ‘SELECT ... WHERE id = {id}’)”;
    }
    }
    rp.Prepare();
    

    (Check the exact Name properties of your three tables in the Dictionary window or in the <TableDataSource Name="..."> XML element of the .frx template.)

This discussion has been closed.