Hi,
i have a problem with a subreport: I created a main report and included a
subreport. The Subreport is linked with the main report over a String field.
The column in the main report has the type uniqueidentifier in the sql-server
database.
if the column in the main report has a value, the subreport works fine. but
if the value is empty, i get the error 'message: error: subreport could not
be shown' in the report and in the visual studio output window i get the
following message:
The expression for the subreport â'subreport1â' contains an error: Object
reference not set to an instance of an object.
Can someone help me how to avoid this error?Here's how I did it:
First, in the dataset of the main report, make sure that the String field
always returns a value, also when the uniqueidentifier column is empty.
Use coalesce(convert(varchar(36), column1), '0') in your query string in
stead of just column1 (supposing that the uniqueidentifier column is called
'column1', and that you are using SQL Server as data source. I dont' know
what other products support the coalesce function).
Next, use an Iif clause as query string for the subreport, like ...
= Iif(Parameters!myparam.value <> '0', "select col1, col2 from table1 where
convert(varchar(36), lookupcolumn) = '" + Parameters!myparam.value + "'",
"select 'unknown', 'unknown')
Lookupcolumn should be the name of the column that matches with the value in
your main report.
Hth,
Flip
"Bernd" wrote:
> Hi,
> i have a problem with a subreport: I created a main report and included a
> subreport. The Subreport is linked with the main report over a String field.
> The column in the main report has the type uniqueidentifier in the sql-server
> database.
> if the column in the main report has a value, the subreport works fine. but
> if the value is empty, i get the error 'message: error: subreport could not
> be shown' in the report and in the visual studio output window i get the
> following message:
> The expression for the subreport â'subreport1â' contains an error: Object
> reference not set to an instance of an object.
> Can someone help me how to avoid this error?
>
No comments:
Post a Comment