This is a migrated thread and some comments may be shown as answers.

Error if there are no data to be displayed in ReportViewer

7 Answers 853 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sunny
Top achievements
Rank 1
Sunny asked on 09 Feb 2009, 11:17 AM
Hello,

When i try to search by passing parameter values to Report, then if there is no result for any particular criteria.
then it gives error ,
              Error : Object Reference not set to an instance of an object.

Please help me to sort out the problem.
What should i do if there are no records to be displayed in specific search Criteria ?.

Thanks.

7 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 10 Feb 2009, 05:33 PM
Hello jaspreet,

Are you using parameterized queries or are you using our report parameters? If the latter, do you have the UI AllowNull and AllowBlank properties of the parameter set to true? Any additional information would be helpful.

Kind regards,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Sunny
Top achievements
Rank 1
answered on 11 Feb 2009, 09:13 AM
Thanks for the Reply,

I am using the Report Parameters, and i had also tried by setting allow blank & allow blank properties set to true.

I have 5 different dropdownlist for passing parameters.I am getting results correctly when there are records to show
in the Report Viewer.

But, when i generate Report and if the datasource returns no records then it gives me error.

Error : An error has occured while processing TextBox 'hotel_nameDataTextBox':
           Object reference not set to an instance of an object.


Please reply me as soon as possible to sort out the problem.

Kind regards,
Jaspreet

0
Steve
Telerik team
answered on 12 Feb 2009, 01:27 PM
Hi jaspreet,

It is job of the developer to handle null and dbnull occurrences for your fields. You can use the IsNull() or IIf() built-in functions for this purpose.
If you're still having problems, please open a support ticket and attach a sample report that replicates the problem.

Regards,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Ricardo Pinto
Top achievements
Rank 1
answered on 20 Feb 2009, 06:58 PM
Hello!

I have exactly the same problem that Jaspreet described:

I have a report which has a parameter ("Report_Param" for instance) and I also set a filter: =Fields.[ID] = =Parameters.Report_Param
Imagine that my ReportDataSet gets 5 records from the database:

ID Col1 Col2 Col3 Col4
1  aa     aa    aa    aa
1  bb     bb    bb    bb
2  cc     cc     cc     cc
2  dd     dd    dd    dd
3  ee     ee    ee    ee

If the report is invoke with ReportParam = 1, 2 or 3 everything works as expected.

However, if the report is invoked with ID=4 then all the textbox bound to Col1 to Col4 get the error Jaspreet wrote:
"An error has occured while processing TextBox 'TextBox34': Object Reference not set to an instance of an object"

If I use the IsNull() function the same error occurs, and if I use the IIf() function I get another error:
"An error has occured while processing TextBox 'TextBox14': The expression contains object 'CCOT_Course_Type_ID' that is not defined in the current context"

I think the problem is happening because in the case that the parameter value does not exist in the dataset (ID=4, for instance), nothing can be bound!

I did the following to prevent the error messages to be displayed:
If Me.ReportDataSet.ReportDataTable.Count > 0 Then
                Me.ReportDataTableAdapter1.Fill(Me.ReportDataSet.ReportDataTable)
            Else
                Me.Report.Visible = False
                MsgBox("No data found", MsgBoxStyle.Exclamation, "Warning")
            End If

But this is a workaround (the report is not shown)!
How can I still show my report but with empty textboxes???

Thanks in advance!
Regards,

Ricardo Pinto.
0
Steve
Telerik team
answered on 23 Feb 2009, 04:58 PM
Hello Ricardo,

If your report parameters are bound to (i.e. have available values), then you should not be able to enter a value that is not available, so this is kind of strange case. We would appreciate it if you prepare and send us a small sample report bound to a dummy datasource that shows the behavior you describe. We would review it and advise you accordingly.

All the best,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Ricardo Pinto
Top achievements
Rank 1
answered on 24 Feb 2009, 07:05 AM
Thanks Steve for your answer.

I'm sorry if I wasn't totally clear! My report parameters do not have available values, I suppose.
I have two properties in the report codebehind (MyReport.vb):

 
Public Property ParamAction() As Integer  
        Get  
            Return CType(Me.ReportParameters(0).Value, Integer)  
        End Get  
        Set(ByVal value As Integer)  
            Me.ReportParameters(0).Value = value  
        End Set  
    End Property 
 
 
Public Property ParamSession() As Integer  
        Get  
            Return CType(Me.ReportParameters(1).Value, Integer)  
        End Get  
        Set(ByVal value As Integer)  
            Me.ReportParameters(1).Value = value  
        End Set  
    End Property 


And in the usercontrol with the report viewer I set:

Dim report As ReportClass.MyReport = New ReportClass.MyReport  
report.ParamAction = currentAction
report.ParamSession = currentSession
Me.ReportViewer1.Report = report 
Me.Page.Title = "My report" 

So my report can receive any values I set in currentAction and currentSession (but these values are limited to the selected rows in a grid).

The problem is I sometimes want to see the report for an action and a specific session (providing both values to both properties), but other times I would like to see all sessions of a specific action (providing a value only to paramAction)

Should I create two separate reports?
Thanks again!

Ricardo.




0
Steve
Telerik team
answered on 26 Feb 2009, 02:28 PM
Hi Ricardo,

Since you are using custom UI/approach to set parameters, it would be your responsibility to take care of the case, when one or all are not set by checking if they have value or provide a default value.
Generally when you have more than one parameter and they are not cascading (i.e. depend on each other like in the Product Line Sales catalog), you can create separate reports.

All the best,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
General Discussions
Asked by
Sunny
Top achievements
Rank 1
Answers by
Steve
Telerik team
Sunny
Top achievements
Rank 1
Ricardo Pinto
Top achievements
Rank 1
Share this question
or