Friday, March 9, 2012

ReportObjectModel.Fields as DataRow?

I have a function in C# that performs some complex calculations given a
DataRow object. I would like to somehow pass in my Fields structure as a
parameter to this function. But, I get a compile error saying cannot convert
Microsoft.ReportingServices.ReportProcessing.ReportObjectModel.Fields to
System.Data.DataRow. So, I changed the parameter from DataRow to Object[].
That does not work either. Finally, I changed the reqd parameter from
Object[] to Object, just to see the contents of the Fields structure. Now,
this compiles but the contents of the structure are really weird! I see
properties named a, b,c,d, e, etc! Is there something I am doing wrong? or
are these the ACTUAL property names' Also, i tried searching all over for
documentation on ReportObjectModel.Fields class but could not find anything.
Any comments/pointers to helpful material would be appreciated.You have to pass-in the field values as arguments to your function. You
cannot just pass-along the entire Fields object (which is an internal
object). The property names you are seeing (through reflection) are
obfuscated internal properties. Only the Field class (but not the Fields
collection) has public properties.
Please check this article for an example how to pass-in values to custom
code:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql2k/html/ERSCstCode.asp?frame=true
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Aparna" <Aparna@.discussions.microsoft.com> wrote in message
news:F3CFC82D-56B5-4449-A2E1-175444E2C508@.microsoft.com...
>I have a function in C# that performs some complex calculations given a
> DataRow object. I would like to somehow pass in my Fields structure as a
> parameter to this function. But, I get a compile error saying cannot
> convert
> Microsoft.ReportingServices.ReportProcessing.ReportObjectModel.Fields to
> System.Data.DataRow. So, I changed the parameter from DataRow to Object[].
> That does not work either. Finally, I changed the reqd parameter from
> Object[] to Object, just to see the contents of the Fields structure. Now,
> this compiles but the contents of the structure are really weird! I see
> properties named a, b,c,d, e, etc! Is there something I am doing wrong? or
> are these the ACTUAL property names' Also, i tried searching all over for
> documentation on ReportObjectModel.Fields class but could not find
> anything.
> Any comments/pointers to helpful material would be appreciated.|||Hi Robert,
I guess what I was trying to achieve was someway of passing the entire
collection of my fields as an array(object[]), so that my custom assembly
code could then map that collection to a datarow. I am aware that I can pass
in the individual field values as parameters, but in that case, what would
happen if I had about 10 field values or 15 or 20..It seems it would be very
inconvenient to pass in that many arguments to a function. I know I could
write en embedded VB function that takes the Fields object as a parameter and
creates an array from it, and pass that array to my custom assembly, but then
I am going to have to rewrite this translation function in every report. Is
there a better way of doing this?
Anyway, thanks for the info about the Fields collection. I have read Teo's
article before but thanks anyway...
Aparna.
"Robert Bruckner [MSFT]" wrote:
> You have to pass-in the field values as arguments to your function. You
> cannot just pass-along the entire Fields object (which is an internal
> object). The property names you are seeing (through reflection) are
> obfuscated internal properties. Only the Field class (but not the Fields
> collection) has public properties.
> Please check this article for an example how to pass-in values to custom
> code:
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql2k/html/ERSCstCode.asp?frame=true
> --
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "Aparna" <Aparna@.discussions.microsoft.com> wrote in message
> news:F3CFC82D-56B5-4449-A2E1-175444E2C508@.microsoft.com...
> >I have a function in C# that performs some complex calculations given a
> > DataRow object. I would like to somehow pass in my Fields structure as a
> > parameter to this function. But, I get a compile error saying cannot
> > convert
> > Microsoft.ReportingServices.ReportProcessing.ReportObjectModel.Fields to
> > System.Data.DataRow. So, I changed the parameter from DataRow to Object[].
> > That does not work either. Finally, I changed the reqd parameter from
> > Object[] to Object, just to see the contents of the Fields structure. Now,
> > this compiles but the contents of the structure are really weird! I see
> > properties named a, b,c,d, e, etc! Is there something I am doing wrong? or
> > are these the ACTUAL property names' Also, i tried searching all over for
> > documentation on ReportObjectModel.Fields class but could not find
> > anything.
> > Any comments/pointers to helpful material would be appreciated.
>
>|||At this point there is no better way of doing this. But even if we would
expose the field values as object array, I don't think it is feasible to
write a generic custom assembly and reuse it for arbitrary reports, because
the custom assembly would need to have metadata about the semantics of the
field values to interpret them correctly.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Aparna" <Aparna@.discussions.microsoft.com> wrote in message
news:0F632520-C6E3-4BB2-AADD-AED858B5370D@.microsoft.com...
> Hi Robert,
> I guess what I was trying to achieve was someway of passing the entire
> collection of my fields as an array(object[]), so that my custom assembly
> code could then map that collection to a datarow. I am aware that I can
> pass
> in the individual field values as parameters, but in that case, what would
> happen if I had about 10 field values or 15 or 20..It seems it would be
> very
> inconvenient to pass in that many arguments to a function. I know I could
> write en embedded VB function that takes the Fields object as a parameter
> and
> creates an array from it, and pass that array to my custom assembly, but
> then
> I am going to have to rewrite this translation function in every report.
> Is
> there a better way of doing this?
> Anyway, thanks for the info about the Fields collection. I have read Teo's
> article before but thanks anyway...
> Aparna.
>
>
> "Robert Bruckner [MSFT]" wrote:
>> You have to pass-in the field values as arguments to your function. You
>> cannot just pass-along the entire Fields object (which is an internal
>> object). The property names you are seeing (through reflection) are
>> obfuscated internal properties. Only the Field class (but not the Fields
>> collection) has public properties.
>> Please check this article for an example how to pass-in values to custom
>> code:
>> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql2k/html/ERSCstCode.asp?frame=true
>> --
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>
>> "Aparna" <Aparna@.discussions.microsoft.com> wrote in message
>> news:F3CFC82D-56B5-4449-A2E1-175444E2C508@.microsoft.com...
>> >I have a function in C# that performs some complex calculations given a
>> > DataRow object. I would like to somehow pass in my Fields structure as
>> > a
>> > parameter to this function. But, I get a compile error saying cannot
>> > convert
>> > Microsoft.ReportingServices.ReportProcessing.ReportObjectModel.Fields
>> > to
>> > System.Data.DataRow. So, I changed the parameter from DataRow to
>> > Object[].
>> > That does not work either. Finally, I changed the reqd parameter from
>> > Object[] to Object, just to see the contents of the Fields structure.
>> > Now,
>> > this compiles but the contents of the structure are really weird! I see
>> > properties named a, b,c,d, e, etc! Is there something I am doing wrong?
>> > or
>> > are these the ACTUAL property names' Also, i tried searching all over
>> > for
>> > documentation on ReportObjectModel.Fields class but could not find
>> > anything.
>> > Any comments/pointers to helpful material would be appreciated.
>>|||Works for me...
I pass a reference to the fields collection to custom code like this
=code.IsValid(Fields)
and recieve it in custom code like this:
Public Function IsValid(f as Fields) as Boolean
If f!MyField.Value < foo then return false
return true
End Function
I use it in the filter expression like this:
Expression =code.IsValid(Fields)
Operator = Value =true
Note that in the filter expression, the "Value" must begin with the equal
sign.
Good Luck,

No comments:

Post a Comment