Results 1 to 6 of 6

Thread: [RESOLVED] Report with NULL parameter

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2016
    Location
    South Africa
    Posts
    141

    Resolved [RESOLVED] Report with NULL parameter

    I have a VB.NET application with reports (using Microsoft Reportviewer).

    I have searched, but cannot find a answer to my problem.

    I want to show all records on the report if the reportparameter is null. I use a combobox to choose the report parameter name.


    Code:
    Dim stringaliasnaam As String
    
    
            If KiesVorm.CmbAliasnaam3.SelectedIndex <> -1 Then
                stringaliasnaam = KiesVorm.CmbAliasnaam3.SelectedItem.ToString
            Else
                stringaliasnaam = Nothing
    
            End If
    
    
            Dim param1 As New ReportParameter("ReportParameterAliasnaam", stringaliasnaam)
    
    
            Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter() {param1})
    
            ReportViewer1.Show()
            Me.ReportViewer1.RefreshReport()

    I set the reportparameter properties to Allow Null.
    In a tablix properties I set the Filter to = isnothing(Parameters!ReportParameterAliasnaam.Value)
    I make the type Boolean. I use = as the operator and the value as =false


    When I run the application, I get no error messages, but the results in the report are wrong. If I select something from the combobox all records are displayed and when I select nothing the report is empty.

    I want the report to display the records for the selection in the combobox and if nothing is selected I want to see all records.

    Can someone please let me know what I am doing wrong ?

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: Report with NULL parameter

    There's a difference between NULL and Nothing. They are not interchangeable nor the same thing. I think that's the problem. You should be passing NULL, not nothing. BUT... you can't assign a NULL value to a String variable... so you'll need to change how you're setting your parameter so you can pass a null.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2016
    Location
    South Africa
    Posts
    141

    Re: Report with NULL parameter

    Thank you for your reply Technome.

    I have replaced nothing with an empty string

    Code:
    If KiesVorm.CmbAliasnaam3.SelectedIndex <> -1 Then
                stringaliasnaam = KiesVorm.CmbAliasnaam3.SelectedItem.ToString
            Else
                stringaliasnaam = ""
    
            End If
    On the report designer I have changed the filter expression as follows :

    Expression : [BlokkeklaarAliasnaam]
    Operator : =
    Valeue : =IIF(Parameters!ReportParameterAliasnaam.Value = "", Nothing, Parameters!ReportParameterAliasnaam.Value)

    I have also set the the parameter properties to allow blank and Null values.

    Now if I make a choice in the combobox, I get the correct result. But if I make no choice the result is empty.

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: Report with NULL parameter

    Null is not nothing
    Nothing is not empty string
    empty string is not null

    NULL <> Nothing <> ""

    Null != Nothing != ""

    They are not the same thing.

    I didn't say to pass in an empty string. I said you need to pass in a null value.
    Code:
    Valeue : =IIF(Parameters!ReportParameterAliasnaam.Value = "", Nothing, Parameters!ReportParameterAliasnaam.Value)
    Still passing in Nothing...
    Try using DBNull...


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2016
    Location
    South Africa
    Posts
    141

    Re: Report with NULL parameter

    Hi Technnome is is really baffling me.

    From your first reply I understand I cannot assign a null value to a string. So I pass only the following :

    Code:
    Dim param1 = New ReportParameter("ReportParameterAliasnaam", KiesVorm.CmbAliasnaam3.SelectedItem.ToString)
    
            Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter() {param1})
    
            ReportViewer1.Show()
            Me.ReportViewer1.RefreshReport()
    What I cannot understand is how to set the filter in the tablix properties. I keep the parameter to Allow Null.
    How do I use DBNull as you suggested?

    I have tried :

    Code:
    =iif(Parameters!ReportParameterAliasnaam.Value = dbnull ,dbnull.value,Parameters!ReportParameterAliasnaam.Value)
    I get the following very long error message :








    Severity Code Description Project File Line Suppression State
    Error The FilterValue expression for the tablix ‘Tablix1’ contains an error: [BC30561] 'dbnull' is ambiguous, imported from the namespaces or types 'System.Convert, System'. LutzvilleProgram D:\Wingerdbou\LutzvilleProgram\LutzvilleProgram\Reports\BlokkeKlaar.rdlc

    Found conflicts between different versions of "Microsoft.ReportViewer.WinForms" that could not be resolved.There was a conflict between "Microsoft.ReportViewer.WinForms, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" and "Microsoft.ReportViewer.WinForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91". "Microsoft.ReportViewer.WinForms, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" was chosen because it was primary and "Microsoft.ReportViewer.WinForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" was not. References which depend on "Microsoft.ReportViewer.WinForms, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" [D:\Wingerdbou\LutzvilleProgram\LutzvilleProgram\packages\Microsoft.ReportViewer.WinForms.v12.12.0.0. 1\lib\Microsoft.ReportViewer.WinForms.dll]. D:\Wingerdbou\LutzvilleProgram\LutzvilleProgram\packages\Microsoft.ReportViewer.WinForms.v12.12.0.0. 1\lib\Microsoft.ReportViewer.WinForms.dll Project file item includes which caused reference "D:\Wingerdbou\LutzvilleProgram\LutzvilleProgram\packages\Microsoft.ReportViewer.WinForms.v12.12.0.0 .1\lib\Microsoft.ReportViewer.WinForms.dll". Microsoft.ReportViewer.WinForms, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL References which depend on "Microsoft.ReportViewer.WinForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" [D:\Wingerdbou\LutzvilleProgram\LutzvilleProgram\packages\Microsoft.ReportingServices.ReportViewerCon trol.Winforms.150.1449.0\lib\net40\Microsoft.ReportViewer.WinForms.dll]. D:\Wingerdbou\LutzvilleProgram\LutzvilleProgram\packages\Microsoft.ReportingServices.ReportViewerCon trol.Winforms.150.1449.0\lib\net40\Microsoft.ReportViewer.Design.dll Project file item includes which caused reference "D:\Wingerdbou\LutzvilleProgram\LutzvilleProgram\packages\Microsoft.ReportingServices.ReportViewerCo ntrol.Winforms.150.1449.0\lib\net40\Microsoft.ReportViewer.Design.dll". Microsoft.ReportViewer.Design, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Nov 2016
    Location
    South Africa
    Posts
    141

    Re: Report with NULL parameter

    OK got it.

    In VB.net :

    Code:
    Dim param1 As New ReportParameter
    
            If KiesVorm.CmbAliasnaam3.SelectedIndex <> -1 Then
                param1 = New ReportParameter("ReportParameterAliasnaam", KiesVorm.CmbAliasnaam3.SelectedItem.ToString)
            End If
    
    
            Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter() {param1})
    
            ReportViewer1.Show()
            Me.ReportViewer1.RefreshReport()
    In other words not not assign a value to the parameter when nothing is selected in the combobox.

    In the report set the parameter to allow NULL.

    Also make the default value of the parameter NULL (This is what I missed)

    In the tablix filter :
    Expression: =IIF(IsNothing(Parameters!ReportParameterAliasnaam.Value), True, Fields!BlokkeklaarAliasnaam.Value=Parameters!ReportParameterAliasnaam.Value)

    Type : Boolean
    Operator : =
    Value : True

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width