Page 1 of 1

Programmatically add the datasource

Posted: Thu Jul 23, 2009 2:39 am
by purs
hello,
i have the report and the databand there. I need to load the report programmatically and add a generated dataset as a datasource to the databand.
Can someone provide a sample code for this?..

for now i do the following:
StiReport report = null;
if (!File.Exists(reportDllName))
{
report = new StiReport();
report.Load(reportName);
report.Compile(reportDllName);
}
else
{
report = StiReport.GetReportFromAssembly(reportDllName);
}
((StiText)report["txtFullName"]).SetText(personRow.FullName);
......
...... // then i have dataset ds and do the following:

report.RegData("Addresses",ds);
report.Dictionary.Synchronize();
((StiDataBand)report["DataBandAddressInfo"]).DataSourceName = "Addresses";

:( but this doesnt seem to work.

Programmatically add the datasource

Posted: Thu Jul 23, 2009 9:40 am
by Jan
Hello,
purs wrote: report.RegData("Addresses",ds);
report.Dictionary.Synchronize();
((StiDataBand)report["DataBandAddressInfo"]).DataSourceName = "Addresses";
After compilation of report following lines of code does not have sense:

Code: Select all

report.Dictionary.Synchronize();
((StiDataBand)report["DataBandAddressInfo"]).DataSourceName = "Addresses";
If you need register new dataset in report datastore instead previously registered dataset you can use following code:

Code: Select all

report.DataStore.Clear();
if (report.CompiledReport != null)report.CompiledReport.DataStore.Clear();

report.RegData("Addresses",ds);
Thank you.

Programmatically add the datasource

Posted: Fri Jul 24, 2009 1:37 am
by purs
that is not exactly what i want..
i want to add datasource to databand programatically and cant access it the way i did :(

Programmatically add the datasource

Posted: Sun Jul 26, 2009 4:00 pm
by Edward
Hi

Please see the UserData sample application from the standard installation.

And also there is a RuntimeBuildReport sample application which assigns a DataSource to the DataBand but only for the report template.

Here is the code from that application:

Code: Select all

//Create Databand
StiDataBand dataBand = new StiDataBand();
dataBand.DataSourceName = "Customers";
dataBand.Height = 0.5;
dataBand.Name = "DataBand";
page.Components.Add(dataBand);
Thank you.

Programmatically add the datasource

Posted: Mon Jul 27, 2009 2:15 am
by purs
Edward, thank you for the answer, but thats not what i want either .. At last i did the following and it works for me:

Code: Select all

ds = new DataSet();
ds.Tables.Add(dt); // dt is filled with addresses datatable 
if (File.Exists("Addresses.xsd"))
 File.Delete("Addresses.xsd");
if (File.Exists("Addresses.xml"))
 File.Delete("Addresses.xml");
ds.WriteXmlSchema("Addresses.xsd");
ds.WriteXml("Addresses.xml", XmlWriteMode.WriteSchema);
and after assign this xml-ed datasource to my databand.

Programmatically add the datasource

Posted: Tue Jul 28, 2009 1:10 am
by Edward
Hi

Thank you for this feedback.

Please let us know if any additional help is required.

Thank you.