Report breaking when data link returns no records
I have a report that pulls a photo in from a data link to a SQL Server database. When there are no records returned by the data link, the report errors out. This is a new behavior I'm seeing in newer viewers. Here's the breakdown of where it works and where it doesn't:
- GE 4.1.2 and GVS 2.2.1 works fine (just no photo in the report)
- GE 4.1.2 and GVH 2.2.1 breaks
- GE 4.2.2 and GVS/GVH 2.3.3 both break
The report works fine in all those versions as long as the data link returns a record. When it breaks, I get a generic "Object reference not set to an instance of an object". I put alerts in right before and after the report activity runs in my workflow. The first one shows up, but the second doesn't, so it has to be breaking when running the report.
Has anyone else seen this behavior?
-
I think I figured out what's breaking it. The photo's pulled into the main report using a sub report. In the sub report, I have a hyperlink on a photo that's created using some code in the scripting tab. If I remove the code, then the report will run fine; there just won't be a photo. I'm guessing it's erroring out because the code in the sub report is trying to assign a hyperlink to an object that doesn't exist.
0 -
Hi John
hope about adding into the script that runs in the sub-report a bit of error checking to handle the no image situation. ie have a 'No image available' image.
Regards
Ralph
0 -
That'd be great; how do I do that?
0 -
Hi John
can you post the script that you have at this point in the subreport?
Ralph
0 -
Here it is. The picture is a photo of a house being pulled from our Assessing dept.'s SQL database. The script calculates a hyperlink to use the property house number and street name to run a Zillow search on it (real estate site for house listings).
public void Detail1_Format()
{
Picture hyperlink1 = rpt.Sections["Detail1"].Controls["Picture1"] as Picture;
string housenum = rpt.Fields["HOUSENUM"].Value as string;
string address = rpt.Fields["ADDRESS"].Value as string;
hyperlink1.HyperLink = "http://www.zillow.com/homes/" + housenum + " " + address + ",-brooklyn-park,-mn_rb/";
}0 -
Hi John
I made a guess at an address to see what gets returned from a Zillow search nad used http://www.zillow.com/homes/100 West Street,-brooklyn-park,-mn_rb/
For a start that url returns an entire web page not just an image.
Is this what you were intending?
For my reports that have an image in I have been using something along the lines of:
public void ActiveReport_ReportStart()
{}
public void Detail1_Format()
{
try
{string housenum = rpt.Fields["HOUSENUM"].Value as string;
string address = rpt.Fields["ADDRESS"].Value as string;
string URL = "http://www.zillow.com/homes/" + housenum + " " + address + ",-brooklyn-park,-mn_rb/theImage.jpg ";//Setting up the image to retrieve webrequest
System.Drawing.Image pinImage = null;
System.Net.WebRequest req = System.Net.WebRequest.Create(URL); //attempt to download image from url
req.Credentials = new System.Net.NetworkCredential("user","pwd","domain");using (System.Net.WebResponse response = req.GetResponse())
using (System.IO.Stream stream = response.GetResponseStream())
{
pinImage = System.Drawing.Image.FromStream(stream);String imgFileName = @"c:\temp\image" + System.DateTime.Now.Ticks.ToString() + ".jpg";
pinImage.Save(imgFileName);//PictureProperty is the name of the Picture control - your's might be a different name
Picture PictureProperty = rpt.Sections["Detail1"].Controls["Picture1"] as Picture;
//PictureProperty.HyperLink = URL;
//PictureProperty.DataField = URL;Image image2 = Image.FromFile(imgFileName);
PictureProperty.Image = image2;
}
}
catch
{
}}
Looking forwward to your comments
Ralph
0 -
The photo on my report is coming from a SQL database actually. The hyperlink is just the action to take when the user clicks the image. I'm not trying to pull an image into the report using the hyperlink. Cool idea though.
I'll try addding the try/catch clauses to my script to see if that fixes it. Thanks as always for the advice.
0 -
Worked like a charm, thanks!
public void Detail1_Format()
{
try
{
Picture hyperlink1 = rpt.Sections["Detail1"].Controls["Picture1"] as Picture;
string housenum = rpt.Fields["HOUSENUM"].Value as string;
string address = rpt.Fields["ADDRESS"].Value as string;
hyperlink1.HyperLink = "http://www.zillow.com/homes/" + housenum + " " + address + ",-brooklyn-park,-mn_rb/";
}
catch
{
}
}0 -
Hi John
glad to hear that it was helpful. As a suggestion you could add in to the catch section
Picture hyperlink1 = rpt.Sections["Detail1"].Controls["Picture1"] as Picture;
hyperlink1.HyperLink = "http://www.zillow.com/homes/"so that the user still gets to the zillow site but types in a address themselves.
Regards
Ralph
0 -
Interesting idea; thanks again. I'll probably try to put some sort of code into the catch section so there isn't just white space there.
0 -
While I have your ear, Ralph, do you have any recommendations for good report designing online resources? I've been able to do a decent amount with Report Designer, but as we all know the help documentation for it is pretty sparse. Where did you learn all of your skills in writing report script code?
0 -
Hi John
I have help from Victoria McDonald (Geocortex Staff), Active Reports website and C# knowledge
Regards
Ralph
0
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.
Kommentare
12 Kommentare