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)
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
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