Report Designer null exceptions
The following formula is provided in the print templates from Latitude for the Sample Sites. It's the MailingAddressCalc formula, but I've modified it slightly by changing the field names and the values in the string that are output, eg. I'm outputting "-" after the UNIT_NUM when it exists.
(UNIT_NUM.ToString().Trim() != "" ? UNIT_NUM.ToString().Trim() + "-" : "") + (STREET_NUM.ToString().Trim() != "" ? STREET_NUM.ToString().Trim() + " " : "") + (STREET1.ToString().Trim() != "" ? STREET1.ToString().Trim() + " " : "")
This works fine for empty fields, but for null value fields it returns an error: "Control Script failed for control".
So instead I tried using IsNot Nothing, as follows.
(UNIT_NUM IsNot Nothing ? UNIT_NUM.ToString().Trim() + "-" : "") + (STREET_NUM IsNot Nothing ? STREET_NUM.ToString().Trim() + "-" : "") + (STREET1 IsNot Nothing ? STREET1.ToString().Trim() + "-" : "")
This didn't return an error for null value fields or empty fields, but it did return a completely empty text box for cases when STREET1 had a value but when UNIT_NUM or STREET_NUM was empty. It should have returned the value for STREET1 only.
I'm using a SQL Server 2008 R2 database.
I need a formula that can handle both null values and empty values. Any ideas as to how I do this?
Thanks
Mark
-
Hi Mark,
You could try something similar to this: Not String.IsNullOrEmpty(_strICAD.Trim())
0 -
Using String.IsNullOrEmpty(_strICAD.Trim()) also returns an error for null value fields, the same as before: "Control Script failed for control".
0 -
I've tried expanding the formula to handle both nulls and empty strings.
(UNIT_NUM IsNot Nothing ? (UNIT_NUM.ToString().Trim() != "" ? UNIT_NUM.ToString().Trim() + "-": "") : "") + ":UNIT, " (STREET_NUM IsNot Nothing ? (STREET_NUM.ToString().Trim() != "" ? STREET_NUM.ToString().Trim() != "" + " " : "") : "") + ":STREET_NUM, " + (STREET1 IsNot Nothing ? (STREET1.ToString().Trim() != "" ? STREET1.ToString().Trim() : "") : "") + ":STREET1."
If UNIT_NUM is an empty string then this returns a completely empty string. It's not even returning the ":UNIT, "
If UNIT_NUM is a null then this is no longer returning an error. However it's also returning a completely empty string in this case too.
The Geocortex log file shows lots of DEBUG messages but no ERROR messages.
0
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.
Kommentare
3 Kommentare