Programmatically add the datasource

Stimulsoft Reports.NET discussion
Post Reply
purs
Posts: 4
Joined: Thu Jul 23, 2009 2:32 am

Programmatically add the datasource

Post 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.
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

Programmatically add the datasource

Post 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.
purs
Posts: 4
Joined: Thu Jul 23, 2009 2:32 am

Programmatically add the datasource

Post 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 :(
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Programmatically add the datasource

Post 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.
purs
Posts: 4
Joined: Thu Jul 23, 2009 2:32 am

Programmatically add the datasource

Post 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.
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Programmatically add the datasource

Post by Edward »

Hi

Thank you for this feedback.

Please let us know if any additional help is required.

Thank you.
Post Reply