Problem with creating report in code

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

Problem with creating report in code

Post by spv123 »

I'm creating a generic reporting form which takes a dataset and lays it out in code on a stimulsoft report. It does this by loading a standard report template which has empty databands and headerbands etc on it. The standard report template has an empty placeholder for an ADO dataset..

I populate the report in code using the following code extracts (this isn't the full code but the "relevant bits"

Firstly to create the dataset, link to the report and link to the databand / headerband (which are both module level variables) for populating later:

Code: Select all

 Dim ds As DataSet
        Dim dv As DataView
        ds = Me.DmsDataSet.Copy
        ds.Tables(0).TableName = "spv"
        dv = ds.Tables(0).DefaultView
        dv.Sort = CType(Me.DataSource, DataView).Sort

        ' Link Dataset to Report
        Me.StiReport1.RegData("spv", dv) 'ds.Tables(0))
        Me.StiReport1.DataStore.RegData("spv", dv) ' ds.Tables(0))

        StiReport1.Dictionary.Synchronize()

        DataBand = CType(Me.StiReport1.GetComponentByName("DataBand1"), Stimulsoft.Report.Components.StiDataBand)
         HeaderBand = CType(Me.StiReport1.GetComponentByName("HeaderBand1"), StiHeaderBand)
       
The columns on the report are created in a for next as follows :

Code: Select all

ColNo = 0
        Dim Heading As String
        For Each dc As DataColumn In ds.Tables(0).Columns
            ' Add Data
            'Heading = dc.ColumnName
            ' dc.ColumnName = "Col" & ColNo
            AddText(dc.ColumnName, PageWidth * ColWidth(ColNo) / TotalWidth, dc.DataType)
            ColNo = ColNo + 1
        Next
And the "AddText" subroutine has code to add the column as follows:

Code: Select all

  Static left As Decimal
        If DataBand.Components.Count = 0 Then left = 0
        Dim DataText As New StiText(New RectangleD(left, 0, Width, DataBand.Height))
        Dim ColHeaderName As String = ColName
        ColName = ColName.Replace(" ", "_")
        ColName = ColName.Replace("/", "_")
        ColName = ColName.Replace("?", "_")
        ColName = ColName.Replace(".", "_")
        Debug.WriteLine("Adding Column " & ColName & " - " & ColHeaderName)

        With DataText
            .Text.Value = "{Spv." & ColName & "}"
            .Name = "DataText" & ColName
            .Font = New Font(.Font.FontFamily, 6, .Font.Style, .Font.Unit)
            Select Case dt.ToString
                Case "System.DateTime"
                    ' Date

                Case "System.Decimal"
                    .HorAlignment = StiTextHorAlignment.Right
            End Select
            '.HorAlignment = StiTextHorAlignment.Left
        End With
        DataBand.Components.Add(DataText)


        ' Add Column Header
        Dim ColText As New StiText(New RectangleD(left, 0, Width, HeaderBand.Height))
        With ColText
            .Text.Value = ColHeaderName
            .Name = "Col" & ColName
            .Font = New Font(.Font.FontFamily, 6, .Font.Style.Bold, .Font.Unit)
            .Font = New Font(.Font.FontFamily, 6, .Font.Style, .Font.Unit)
            Select Case dt.ToString
                Case "System.DateTime"
                    ' Date

                Case "System.Decimal"
                    .HorAlignment = StiTextHorAlignment.Right
            End Select
            '  .HorAlignment = StiTextHorAlignment.Left
        End With
        HeaderBand.Components.Add(ColText)

This generally works well... until I have data column names that seem to cause a clash in stimulsoft.

For example, a table column with a column name of "Date" causes the following errors in the output window of the visual studio debugger:

2007:05:15, 08:53: StiReport: Compiling report
2007:05:15, 08:53: StiReport: C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\gbfqwvtu.0.vb(127,0) : error BC30456: 'Date' is not a member of 'Reports.Report.spvDataSource'.
2007:05:15, 08:53: StiReport: C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\gbfqwvtu.0.vb(683,0) : error BC30183: Keyword is not valid as an identifier.
2007:05:15, 08:53: StiReport: Compiling report...ERROR
2007:05:15, 08:53: StiReport: Method : [Compile] : C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\gbfqwvtu.0.vb(127,0) : error BC30456: 'Date' is not a member of 'Reports.Report.spvDataSource'.C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\gbfqwvtu.0.vb(683,0) : error BC30183: Keyword is not valid as an identifier.
====================================================
at Stimulsoft.Report.StiReport.Compile(String path, Stream stream, StiOutputType outputType, Boolean autoCreate)
====================================================

and a msgbox pops up with a similar error.

I'm guessing that this is because "Date" is a vb.net keyword? What is the solution to avoid the issue?

Many thanks in advance

Simon



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

Problem with creating report in code

Post by Edward »

To avoid this issue please place @ symbol before the column name. For example - @class or @Date.

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

Problem with creating report in code

Post by spv123 »

Edward,

Thanks for the reply, still a little confused.

I'm presuming your referring to the code lines :

Code: Select all

With DataText
            .Text.Value = "{Spv." & ColName & "}"
I've tried putting the @ infront of the "Spv" - ie "{@Spv." & ColName.... and also right in front of the column name ie "{Spv.@" & ColName

However, both come up with an error on compile saying "Character is not valid" which I presume refers to the "@" character.

Have I understood you correctly?

Thanks
Simoon
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Problem with creating report in code

Post by Edward »

I did not understand the problem in details.
I is clear now.
We will prepare a patch for this issue in a week.

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

Problem with creating report in code

Post by Edward »

We've extended the Columns properties in the following way:
Image

NameInSource property allows to address directly the field in the underlying datatable/query. It is not a problem when the name of the field is the same as the reserved word in .Net. In that case you need to change the name of the "Name" property of the Column.

Thank you.
Post Reply