Showing posts with label shared. Show all posts
Showing posts with label shared. Show all posts

Tuesday, March 27, 2012

Embedded Code: whats the trick?

OK, I give up -- I can't get this to work. I am trying to put the following function into my report (RS 2005):

Public Shared Function ReportTotal(ByVal IsUnitCost As Boolean,ByVal TotalDirectCosts As Double, ByVal SalaryBenefitsTotal As Double, ByVal IndirectRate As Double, ByVal SS_Screened As Integer, ByVal UnitRate As Double) As Double
If IsUnitCost Then
Return SS_Screened * UnitRate
Else
Return TotalDirectCosts + SalaryBenefitsTotal * IndirectRate
End If
End Function

Supposedly, to use this code you put something like this for the expression in one of your fields: =Code.ReportTotal(...paramaters...)

However, when I type in "Code.", "ReportTotal" is not in the list provided by the Intellisense. If I type it in anyway, there is a red squiggly line under "ReportTotal", and then if I try to preview the report, I get an error: "The definition of report [report name] is invalid. Exception of type 'Microsoft.ReportingServices.ReportProcessing.ReportProcessingException' is thrown".

Real helpful. Does this mean there's an error in the Visual Basic? I tried to access the function improperly? What?

I tried with and without "Public", with and without "Shared". Same result.

Can anyone help??

I'm not familiar yet with 2005, but in 2000, there is a tab in the 'Report Properties' dialogue under the 'Report' menu.

If you put the code in there, IE:

Function FormatDateInterval(ByVal value As DateTime) As String
Return Year(value) & "-" & Month(value)
End Function

You can call the function by using something like:

= Code.FormatDateInterval(First(Fields!SaleDate.Value, "Foreclosures"))

Like I said, it works well in 2000. Hope it helps.

|||

Actually I found the answer. My code was fine -- it just doesn't get compiled until you deploy the report. I was testing it out in "preview" mode, and that's why it wasn't working.

Needless to say, this little feature is not documented anywhere!

sql

Embedded Code Executing SQL

I'm trying to execute a stored procedure in the header section of a report
(so I can't use a dataset in the data tab) using the shared datasource of the
report. Does anyone have a simple example executing SQL from the embedded
code of a report?Bryan,
You can use the objects from the detail section to show in the header
or...try to have a select statement in the code behind function.
if u are okay with the first line, just pop up again, i will check and give
u the code
"Bryan" wrote:
> I'm trying to execute a stored procedure in the header section of a report
> (so I can't use a dataset in the data tab) using the shared datasource of the
> report. Does anyone have a simple example executing SQL from the embedded
> code of a report?