In my previous article you saw how to validate a date parameter in SSRS parameter validation using custom code.
Now in this article we will see how to validate a numeric parameter value.
Let's start.
Step 1
We need to write VB code to validate the value as numeric. Here's the VB code to validate the numeric value.
- Function IsInputNumeric(Number1 As String,Number2 As String) As String
- Dim RetValue As String
- If (IsNumeric(Number1) and IsNumeric(Number2)) Then
- RetValue="Valid"
- Else
- RetValue="Please Enter Valid Order ID!!"
- End If
- Return RetValue
- End Function
Function DescriptionI have written IsInputNumeric functions that accept the two parameters Number1 and Number2, then I use the IsNumeric built-in function of VB to validate each number parameter and return a message accordingly.
NoteIn the preceding function I have used two parameters for validation. You can use any number of parameters depending on requirements.
Step 2Then we need to create one parameter, IsValidNumber, whose datatype should be Text and the visibility of the parameter should be Internal.
Then go to the default values tab and specify a value and then call this function over here.
Step 3
After the preceding step we need to validate both parameters before passing to the dataset. Click on the button and write an expression.
Step 4Now we need to add a TextBox to the SSRS report design and then go to the TextBox properties window and call the IsvalidNumber parameter in the value expression of the TextBox and then set the visibility of the TextBox.
Step 5Then preview the SSRS report and test the preceding logic. Here I put a string in both TextBoxes but my query accepts only a numeric value. So this message is for our user.