Page 1 of 2

Problem Creating Report in Code

Posted: Fri Jun 01, 2007 2:20 pm
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

Problem Creating Report in Code

Posted: Tue Jun 05, 2007 12:35 am
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.

Problem Creating Report in Code

Posted: Wed Jun 06, 2007 4:02 am
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

Problem Creating Report in Code

Posted: Wed Jun 06, 2007 4:57 am
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.

Problem Creating Report in Code

Posted: Wed Jun 06, 2007 5:30 am
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.

Problem Creating Report in Code

Posted: Thu Jun 07, 2007 4:23 am
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

Problem Creating Report in Code

Posted: Fri Jun 08, 2007 9:38 am
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.

Problem Creating Report in Code

Posted: Mon Jun 11, 2007 3:34 pm
by Vital
Problem fixed. Thank you for your help.
Patch will be available in build from 12 June.

Thank you.

Problem Creating Report in Code

Posted: Tue Jun 12, 2007 2:58 pm
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

Problem Creating Report in Code

Posted: Tue Jun 12, 2007 3:32 pm
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.