Handling Non Standard Types in RDLC files - reportviewer

I am experiencing a strange issue where a report run locally on one machine works fine, bit on another outputs '#error' when dealing with any fields that are of a type other than the usual string, date or integers. An example is a Field with a type of System.Collections.Generic.List`1[System.String] that is passed through some custom code as below
<Field Name="Equipment">
<DataField>Equipment</DataField>
<rd:TypeName>System.Collections.Generic.List`1[System.String]</rd:TypeName>
</Field>
<Value>=Code.PrintList(Fields!Equipment.Value)</Value>
<Code>
Function PrintList(ByVal listToPrint As System.Collections.Generic.List(Of String)) As String
Dim sb As new System.Text.StringBuilder
For Each s As String in listToPrint
sb.Append(s).AppendLine()
Next
return sb.ToString
End Function
</Code>
On one machine this works fine, but on another only #error is output. I am referencing the full namespace of all types so i cant understand why this would work/not work on one machine to another.
Any ideas?
Cheers

Related

Convert .ToHashset Result from (Of Char) to (Of String)?

I'm not real experienced in using Linq, and am trying to understand .ToHashSet.
I'm using VB for this.
I have this code:
' Import the list of Windows Classes to exclude; one per line.
Dim strRead As String = My.Computer.FileSystem.ReadAllText("C:\Exclude.txt")
' Split the string into a string array
Dim strExcludes As String() = strRead.Split(ControlChars.CrLf.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
' Convert the String Array to a HashSet (Traditional Method)
Dim lList As New HashSet(Of String)(strExcludes)
This works as intended; I get each line from the text file into the HashSet as 1 line per Key.
Now, I want to see how to do the same using .ToHashSet. The following code seems to work fine with the exception of it returning as type <Of Char>, so I get each character in it's own Key, rather than each line in it's own Key.
' Convert the String Array to a HashSet (Using System.Linq Method) (Unfinished: Works, but needs to be converted from Char to String)
Dim lListLinq = strRead.ToHashSet()
I've Googled, and fought with it a bit, trying to get it to return as type <Of String>, but not much Google info out there for .ToHashSet for VB, or really much in C# either regarding this particular problem. I'm not seeing where to do the conversion; .ToHashSet itself also accepts no arguments.
Anyone know what I'm missing? I have a feeling it's something real simple slipping by me.
Invoking ToHashSet() on a string will yield a HashSet(Of Char) and will not give the expected result as you've witnessed.
Instead, what you need to do is split the string returned by ReadAllText and then call ToHashSet() on it to get a HashSet(Of String).
strRead.Split(ControlChars.CrLf.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToHashSet()

VB.NET: Error: 'Cannot be converted to Boolean' when trying to pass list/array of strings

I'm trying to pass a list/array of strings to a public sub in a public module.
form 1:
Dim myList As New List(Of String) From {"Name", "ShortNo", "test1", "test2"}
Validate(myList)
form 2: (Public module)
Public Sub Validate(ByVal Input As List(Of String))
msgbox("Hi")
End sub
All I want to do is pass these strings to the public module in the form of a single package i.e an array of strings or list. I've been fiddling for the last hour or two and keep getting the same error with both. I'm definitely just doing something stupid here.
I've managed to get it to not throw an error, but when I got that working it would just skip over the sub? So I have no idea. (if someone could also explain why vb.net would run past code without calling the sub, that would be great)
Call it as below. It works for me. Fully qualify method call is required in order to stop the ambiguity.
Form2.Validate(myList)

Error using isNumeric() in VB

I am using the IsNumeric() function in visual basic 2012.
my code is this
Dim input As String = "123"
If isNumeric(input) Then
'number codes
Else
'not a number codes
End If
and i'm getting an error on the isNumeric(input) part
isNumeric is a namespace and cannot be used as an expression
i just want to know what is wrong with this, i cant find any documentation that this function has already changed or something.
It sounds like you've created a name clash. You have presumably named your project 'IsNumeric'. The root namespace for the project is named after the project by default so you now have a root namespace named 'IsNumeric' and that takes precedence over the IsNumeric method.
There are a number of options to fix this. Firstly, you can change the root namespace for the project to something other than 'IsNumeric', which you would do in the project properties. Alternatively, you can qualify the method name with its namespace, its module or both, i.e. use Microsoft.VisualBasic.IsNumeric, Information.IsNumeric or Microsoft.VisualBasic.Information.IsNumeric.
I'd tend to suggest not using IsNumeric anyway. It can't distinguish between types of numbers and provides no access to the actual numeric value. If you need to do any of that sort of thing then call the appropriate TryParse method instead, e.g.
Dim number As Double
If Double.TryParse(someText, number) Then
'The input was a valid Double and the value is in 'number'.
Else
'The input was not a valid Double.
End If
Note that IsNumeric actually calls Double.TryParse internally and is the reason it was created in the first place. That's why calling IsNumeric and then something like CDbl is bad: you're parsing the same text twice in that case.
It's very strange, because IsNumeric is a standard function available in VB.Net. Try to create a new console application:
Sub Main()
Dim str As String = "123"
If (IsNumeric(str)) Then
End If
End Sub
For me it works.

How to use Lambda functions with embedded code in SSRS 2008 R2 reports?

Using SSRS 2008 R2 with embedded code, the VB.Net code compiler seems to err whenever I need to do anything beyond the simplest of statements.
For instance, I want to use the LINQ Select function to perform some operations on the elements of a collection, but BIDS keeps throwing compiler errors on lines of perfectly valid VB.Net code.
Public Function SplitToIDs(ByVal multiValue As String) As Integer()
Dim regex As New System.Text.RegularExpressions.Regex("((?>.*?);#\d*;#)", System.Text.RegularExpressions.RegexOptions.Compiled Or System.Text.RegularExpressions.RegexOptions.ExplicitCapture Or System.Text.RegularExpressions.RegexOptions.CultureInvariant Or System.Text.RegularExpressions.RegexOptions.IgnoreCase)
Dim results As New System.Collections.Generic.List(Of String)()
Dim matches As System.Text.RegularExpressions.MatchCollection = regex.Matches(multiValue)
For Each mvMatch As System.Text.RegularExpressions.Match In matches
results.Add(mvMatch.Value)
Next
'Dim pairs As String() = SplitToPairs(multiValue)
'Dim names As System.Collections.Generic.IEnumerable(Of Integer) = System.Linq.Enumerable.Select(pairs, Function(p) Integer.Parse(Microsoft.VisualBasic.Split(p, ";#")(1)))
Dim names As System.Collections.Generic.IEnumerable(Of Integer) = System.Linq.Enumerable.Select(results, Function(p) Integer.Parse(Microsoft.VisualBasic.Split(p, ";#")(1)))
Return System.Linq.Enumerable.ToArray(names)
End Function
On the line 42, which is the comment immediately above where I call System.Linq.Enumerable.Select, Visual Studio 2008 (the VS Shell installed by SQL Server 2008 R2), gives this error when I attempt to preview my report:
An error occurred during local report processing.
The definition of the report '/XXXX' is invalid.
There is an error on line 42 of custom code: [BC30201] Expression expected.
I have already learned that [BC30201] is a generic error with little relation to a missing expression. As seen in my code, I have fully namespace qualified every function or variable beyond the most basic System namespace classes. In the Report Properties dialog, References tab, I've already referenced both mscorlib and System.Core to make sure all the functions I'm using in my code can be resolved to a System assembly.
So a few questions...
Can Anonymous Functions be called and used in SSRS 2008 R2 Reports' embedded code?
In getting to this point, I was getting the same [BC30201] error when I attempted to call one method in the embedded code from another. Yet, I was sure I had some simpler methods in an earlier iteration of this report (or another report) were this actually worked... Should we be able to call one custom method from another within the embedded code?
Notes:
I'm highly tempted to create a separate code module, but I really don't want to fight the political battle necessary to convince lots of people that we should install custom assemblies on our Reporting servers. But unless, I can call those assemblies directly from various report expressions, I may still need to use the embedded code to make the assemblies' methods available to the report.
The source data comes from a SharePoint 2010 list. Many of the columns are Lookup columns that allow multiple values. The method above strips out the delimiters and values to return a collection of IDs.

Report Viewer - Object With Nested List Objects

I have an existing class structure in place and want/need to use that as a data source for a series of reports using vb and 2005, (though we are almost ready to move to 2010, so if that will solve this ill move today!)
Using gotreportviewer sample for nested objects ive added a reportmanager class exposing a getdata method which ive populated with all my data and returned a list(of object). the data is there and correct at the point of databinding, i can add and reference top level properties, however not matter what syntax i try i cant reference the fields in nested classes/lists. I get various messages ranging from "#Error" in the ouput field to nothing, to wont compile.
my class structure is roughly this in short form:
Assembly0
Class ReportManager
TheData as List(Of Object)
New() 'that populates TheData from the class structure below
GetData() as List(of Object)
Assembly1
Class Test
aProperty1 as String
aProperty2 as Int
aProperty3 as String
aProperty4 as String
aProperty4 as List(of aType1)
Assembly2
Class AaType1
aProperty1 as String
aProperty2 as Int
aProperty3 as String
aProperty4 as String
aProperty4 as List(of aType2)
aProperty4 as List(of aType3)
aProperty4 as String
Assembly3
Class aType2
aProperty1 as Boolean
aProperty1 as String
you get the idea
and so on.....
in my main app
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Create an instance of our ReportManager Class
Try
' trust assemblies used in get data
ReportViewer1.LocalReport.ExecuteReportInCurrentAppDomain(Assembly.GetExecutingAssembly().Evidence)
ReportViewer1.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("assy1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1234")
ReportViewer1.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("assy2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1234")
' etc through ALL dependant assemblies
' create datamanager, that will populate its TheData property
Dim reportMan As Data.Reporting.Manager = New Data.Reporting.Manager(18) ' test id sent
' this is the method from the gotreportviewer sample, which only allows you to reference top level properties, regardless of syntax used. i.e. =Fields!Prop.Value.SubProp
' doesnt work
'ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("DummyDataSource", reportMan.GetData))
'Me.ReportingDataBindingSource.DataSource = reportMan.GetData
' this is the only method I have found that allows me to reference an objects nested property and its fields.....?
Data = reportMan.GetData()
Me.ReportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local
Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("Data_Reporting_ReportingData", Data))
' fortnatley there is only ever one test in the list, HOWEVER there will be 4 specimens and n stages below that and so on..
Dim SpecimenData As SpecimenList = Data(0).Specimens
Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("Tests_Specimen", SpecimenData))
' so this method is no good either. currently only a test its just returning the first specimen.
'Dim StageData As Tests.Stages = Data(0).Specimens(0).Stages
'Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("Tests_Specimen", SpecimenData))
' render report
Me.ReportViewer1.RefreshReport()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Fixes i found online/googling:
You must add "ExecuteReportInCurrentAppDomain",
done that no difference.
You must add
Assembly: AllowPartiallyTrustedCallers() to AssemblyInfo.vb, No difference.
You must strongly name you dependent assemblies, done that and it did get rid of
an error regarding a call being made in the "Code" property of the report
(for localization).
have tried the =Fields!Property.Value.SubProperty syntax and it DOESN'T work! no matter what variation I try.
' in the rdlc - this syntax works for a top level properties
=Sum(Fields!TestVersion.Value, "Data_Reporting_ReportingData")
' using the alternate method list in the above code this works
=First(Fields!Index.Value, "Tests_Specimen")
' but these dont for its child properties
=First(Fields!Specimens.Value.Index, "Data_Reporting_ReportingData")
=Fields!Specimens.Value.Index
=Fields!Specimens.Value.Index.Value
So does that mean I have no choice but to create something like
Dim SpecimenData As Tests.SpecimenList = Data(0).Specimens for every single nested object? Also for obvious reasons I'd rather not have to flatten the entire datastructure as it's massive.
I have tried everything I can find on this, not much out there and everything points back to the same three four articles/blog posts that just aren't working for me, their samples unmodified work, but none of them work when applied to nested lists or nested objects of inherited list types.
Does anyone have any sample code of using objects with nested lists that actually works? as none of the ones I could find online work with anything but the simplest of scenarios. i.e. one assembly, or one code file or no nested lists or simple/native types.
I've been at this the best part of A WEEK! I'm now bald and stressed please help.
Failing that can anyone suggest a thrid party vendor that does support this sort of thing?
does crystal? pebble?
Apologies for the wall of text...
Matma
I´m Looking for almost the same, except, that I have objects that have as property other objects, no List of objects, any way, you asked if Crystal Reports do this kind of thing, YES IT DOES, it´s a little bit difficult to do it, but it does.
I don´t know why it´s so difficult to work with that kind of think on now days. Because we are aways working with persistance Frameworks, like Entity Framework, and others, so, you do a hell of a job with a Persistance, and when you go to reports, you need to back to your DataBase model if you want easy work! So waste of time!
I Just have found, it´s possible to do it in report viewer, But it had a problem in visual studio 2010, it´s fixed in SP1 but you need to set all your classes that are used as nested objects as Serializable
Please read : http://wraithnath.blogspot.com.br/2011/04/reportviewer-object-datasource-nested.html