Problem Creating Report in Code

Stimulsoft Reports.NET discussion
spv123
Posts: 26
Joined: Mon Oct 02, 2006 8:07 am
Location: Sheffield, UK

Problem Creating Report in Code

Post by spv123 »

This is a follow on from thread : http://forum.stimulsoft.com/Default.aspx?g=posts&t=574 . You have kindly added the "Name in Datasource" to the dialog box for creating members of a datatable.

I'm just not sure how I would utilise this property in my code (see the thread for the code).

For reference, I'm using a standard template for generating reports, and then building columns in code from a datatable. Therefore, the simulsoft report has a datatable defined with no members, and I'm simply referencing the colums in the "text.value" property of the column definition. I can't see how I would utilise the "Name in Datasource" property.

Can somebody give me a pointer on how I would use this new property in my code to get round the problem that I am experiencing (using reserved words such as "Date" as column names in the dataset).

Many thanks in advance
Simon Verona
Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

Problem Creating Report in Code

Post by Vital »

You can use this property of data column when name of column conflict with c# (or vb.net) keywords. For example you have column with name "void". In this case you can set for this datacolumn name to "myvoid" or "voidcolumn". In property Name in Source you save previous value - "void". Report engine will be use property Name in source to find column in original data table and property Name to reference column in report.

Thank you.
spv123
Posts: 26
Joined: Mon Oct 02, 2006 8:07 am
Location: Sheffield, UK

Problem Creating Report in Code

Post by spv123 »

I'm a little confused. I understand the concept but can't work out how to engineer it in my code.

I believe that I need to redo this portion of my code which loads the datatable into the stireport :

Code: Select all

' Link Dataset to Report
        Me.StiReport1.RegData("spv", dv) 'ds.Tables(0))
        Me.StiReport1.DataStore.RegData("spv", dv) ' ds.Tables(0))
        StiReport1.Dictionary.Synchronize()
I'm presuming that the "Synchronize" function on the dictionary is automatically loading all the columns from the table into the dictionary. I'm guessing that I need to do this manually (I intend to name the columns col1, col2 ... etc. and make them point to the "real" column names).

I just can't work out the code I need to write to do this! Can you give me a further pointer?

Thanks in advance
Simon
Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

Problem Creating Report in Code

Post by Vital »

Following lines of code is equal. So you need remove one of it:

Code: Select all

Me.StiReport1.RegData("spv", dv) 'ds.Tables(0))
Me.StiReport1.DataStore.RegData("spv", dv) ' ds.Tables(0))
Please send to us final version of your report, we will examine it.

Thank you.
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Problem Creating Report in Code

Post by Edward »

Also please note that when you set the Name property of the StiDataColumn, the NameInSource property is also changed, so if the Name and NameInSource have an equal value in that case NameInSource should be reassigned, e.g.:

Code: Select all

(Categories.Columns["CategoryID"] as StiDataColumn).Name = "MyDate";
(Categories.Columns["MyDate"] as StiDataColumn).NameInSource = "Date";
in other case, after the following code:

Code: Select all

(Categories.Columns["CategoryID"] as StiDataColumn).Name = "MyDate";
the NameInSource will be also set into "MyDate"

Thank you.
spv123
Posts: 26
Joined: Mon Oct 02, 2006 8:07 am
Location: Sheffield, UK

Problem Creating Report in Code

Post by spv123 »

Ok , I'm still confused!!!! The code for my report is on the thread http://forum.stimulsoft.com/Default.aspx?g=posts&t=574.

Edward - I understand your tip about changing the nameinsource after setting the name, but I can't work out how to access these properties....

I've tried looking at StiReport1.DataSources("spv").Dictionary.Variables (Spv is my dataset name) to see if that lets me access the columns but it appears to be empty. What should I be using instead? (my c# isn't that good, but it looks like you are using an object called "Categories", but I can't work out what that is?).

Thanks in advance, sorry if I'm being stupid!.
Simon
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Problem Creating Report in Code

Post by Edward »

The issue with setting NameInSource property from the code is confirmed.

We will inform you in that topic when the solution will be ready.

Thank you.
Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

Problem Creating Report in Code

Post by Vital »

Problem fixed. Thank you for your help.
Patch will be available in build from 12 June.

Thank you.
spv123
Posts: 26
Joined: Mon Oct 02, 2006 8:07 am
Location: Sheffield, UK

Problem Creating Report in Code

Post by spv123 »

Thanks for the new version, however I'm still confused!

Once I've populated my dataset by loading a table and syncronising the dictionary, how do I enumerate the datacolumns to rename them and use the new NameInSource property (I plan to name the columns col1, col2, col3 etc and just point all the columns to their real names.

Just to be clear, my project is in vb.net and is outside of the stireport - ie I'm loading up the report in my vb.net project and manipulating the properties from there - I hope that that makes sense.

Many thanks in advance

Simon
Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

Problem Creating Report in Code

Post by Vital »

You can use following code:

Code: Select all

foreach (StiDataSource dataSource in report.Dictionary.Datasources)
foreach (StiDataColumn dataColumn in report.Dictionary.Columns)
{
......
}
For also you can get build from 13 June (when it will be available). This build automatically check all column name on equaling to keywords.

Thank you.
Post Reply