Page 1 of 1

Dynamic creation of report vs data source

Posted: Fri Mar 28, 2008 6:06 am
by igor.kersic
Hi,

I'm just a begginer in using stimul soft (my company bought it now), but I need to work with it to create custom report and dynamic reports.
What do I need: I need to create on-fly dynamic report class that I will show in StiReport preview control. It will show
simple types of charts (bars, clustered columns and pies) and data band which will represent DataSet table data.
Now I've created my class inhereted from StiReport class and I've created (dynamically) charts and table (depending on user data set entered).
But the problem I have is this: when I register RegData my DataSet to report and choose for chart : argument column to be column of a table and value column to be aslo column from a table, and when I do Render() on my custom report class I get "Specific cast invalid" exception which I guess means this:
Report can't convert my DataSet.Table columns to StiDataTableSource. Now I've tried to do something like this

Code: Select all

DataTable sourceTable = reportDataSource.Tables[0];
			StiDataTableSource destinationTable = stiReportDataSource;

			foreach (DataColumn column in sourceTable.Columns)
			{
				StiDataColumn stiColumn = new StiDataColumn(column.ColumnName, column.ColumnName, column.ColumnName, column.DataType);
				destinationTable.Columns.Add(stiColumn);
			}

			this.DataSources.Add(stiReportDataSource);
But after compile/render of report I get "Invalid token ';' in class, struct, or interface member declaration" in some temporary file used by sti report library....

Please where am I getting this wrong? Is there some method to convert DataTable (.net) to StiDataTableSource. Or I have to create my own properties in my custom StiDataTableSource which will use something like:

Code: Select all

((string)(StiReport.ChangeType(this["Name"], typeof(string), true)));
So, in short, I need to conect .NET DataTable object to sti report dynamically and create Charts / Table from it (also dynamically).
In addition I've looked where the problem is with invalid casting (with Reflector) it seems to be in RenderChart method, but the method is huge, so I really don't know what could be the problem..

Please advise,
Thank you very much in advance!
Igor

Dynamic creation of report vs data source

Posted: Sat Mar 29, 2008 3:36 am
by Vital
Hello Igor,

You can use method Synchronize of report dictionary for creating datasources in report. For example:

Code: Select all

StiReport report = new StiReport();
report.RegData(dataSet);
report.Dictionary.Synchronize();
Please see attached sample project.

Thank you.

Dynamic creation of report vs data source

Posted: Mon Mar 31, 2008 5:08 am
by igor.kersic
Hi Vital,

Exactly what I needed! You've been a great help Vital, thanks alot!

Many thanks again,
Igor


Dynamic creation of report vs data source

Posted: Mon Mar 31, 2008 9:23 am
by Vital
Hello,

Please contact us if you need any help.

Thank you.