SSRS: Report loading external images, image not found, can I hide the image control - image

My SSRS report loads logo images for each customer from a customer number specific folder on the report server.
I write an expression, to form my URL to the image based on th customer number.
..."http://localhost/images/" + iCustomerNumber.ToString() + "/logo.gif"
I am able to get this working, but the problem I face is, when a particular customer doesn't has an image, then my report shows a red X mark in place of the logo. In this case, I expect to hide the image control itself. Any thoughts????
The other dirty solution will be to ensure that each customer specific folder has the designated image! even if there is no logo for a customer, I'll place a blank.gif or a spacer.gif of probably a square pixel in dimension!.

You could try adding some custom code and use this in the Image.Value property to load a default image if no image is found:
Public Function GetImage(ByRef CustomerNumber As String) As String
' Customer image
Dim ImageCustomerURL As String
ImageCustomerURL = "http://localhost/images/" + CustomerNumber + "/logo.gif"
' Default Image if customer image does not exist
Dim ImageDefaultURL As String
ImageDefaultURL = "http://localhost/images/default.gif"
' Create a web request to see if customer image exists
Dim m_Req As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(ImageCustomerURL)
Try
Dim HttpWResp As System.Net.HttpWebResponse = CType(m_Req.GetResponse(), System.Net.HttpWebResponse)
If HttpWResp.StatusCode = System.Net.HttpStatusCode.OK
Return ImageCustomerURL
Else
Return ImageDefaultURL
End If
Catch ex As System.Net.WebException
If ex.Status = System.Net.WebExceptionStatus.ProtocolError Then
Return ImageDefaultURL
End If
End Try
Return ImageDefaultURL
End Function
Then your Image.Value property expression is:
=Code.GetImage(iCustomerNumber.ToString())
Edit: Set the Visibility.Hidden property rather than use a default image
Well, I thought it might be nicer to have a default image rather than a blank space but it's really the same idea:
Public Function HideImage(ByRef CustomerNumber As String) As Boolean
' Customer image
Dim ImageCustomerURL As String
ImageCustomerURL = "http://localhost/images/" + CustomerNumber + "/logo.gif"
' Create a web request to see if customer image exists
Dim m_Req As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(ImageCustomerURL)
Try
Dim HttpWResp As System.Net.HttpWebResponse = CType(m_Req.GetResponse(), System.Net.HttpWebResponse)
If HttpWResp.StatusCode = System.Net.HttpStatusCode.OK
Return False
Else
Return True
End If
Catch ex As System.Net.WebException
If ex.Status = System.Net.WebExceptionStatus.ProtocolError Then
Return True
End If
End Try
Return True
End Function
Then your Visibility.Hidden property expression is:
=Code.HideImage(iCustomerNumber.ToString())

Related

How to hide the whole sobject if there is no record in the object in vf page?

my case is to create resume in vf page with renderas pdf.
In that candidate__c, carrersummary__c,Certification__c,WorkExperience__c,etc are my custom objects.
Candidate__c is parent and other objects are child.
what i want is to hide certification object in pdf if there is the candidate has no certification.
certification is a list which has cetification name,validity,credential id which is in controller class.
code in controller class.
List<Certifications__c> certificationsList = [select id,Name,Credential_ID__c,Certifications_Validity__c from Certifications__c where Candidate__r.id=:cid];
clist =new list<Certifications__c>();
for(Certifications__c c:certificationsList){
date dt = c.Certifications_Validity__c;
String s = dt.year() + '/' + dt.month() + '/' + dt.day();
c.certificateexpiredate__c = s;
clist.add(c);
}
vf page:
<apex:variable value="{!clist}" var="cl" >
<apex:outputpanel rendered="{!If(cl!= null, true, false)}">
i used like this...bt this wont work properly.
Help me out of this.
Thanks in advance.

Retrieving Only Selected Field Using LINQ

i have a problems regarding on filtering my code in retrieving companyName from its table..when i query here is the result .. please see my code
Sub call_customers(ByVal dgv_customers As DataGridView)
Dim customers_name = From cust In dbcon.Customers _
Select cust.CustomerID, cust.CompanyName Order By CompanyName Ascending
dgv_customers.DataSource = customers_name
End Sub
the display is CustomerID and CompanyName.. yeah its true.. no problem with the code..
and if i only select cust.companyname the result is this ....like this code
Sub call_customers(ByVal dgv_customers As DataGridView)
Dim customers_name = From cust In dbcon.Customers _
Select cust.CompanyName
dgv_customers.DataSource = customers_name
End Sub
the output is this...
enter image description here
no display and it says length.. why? newbie in LINQ sir ..
please help..
Originally, you were giving the grid an object, and it was displaying each of the properties of that object.
Now that you are giving it a string, it is doing the same thing, but now, the only property on the string is the length,

LINQ to SQL, Visual Basic - Listbox Receives the Query NOT the Result

Overview
This is a homework assignment using LINQ to SQL in a Visual Basic application. It is correct in most ways except that I have a partially broken result. Rather than adding the result of my second query to my listbox, my code adds a weird representation of the query itself. Below is a description of the DB, followed by my output (intended and actual), and finally my code. Please point me toward the broken concept so I can figure out what I am missing. Thanks much.
DB info
I am using two tables, called Members and Payments, from one DB. Members has a primary key called ID and also has the fields first_name and last_name. Payments has a foreign key called Members_Id, which is associated to the Member's primary key; Payments also has the payment values under the column Payments.
Output should be like this
Member name = John Smith
$48.00, 10/20/2005
$44.00, 3/11/2006
But is this instead
Member name = SELECT ([t0].[First_Name] + #p1) + [t0].[Last_Name]
AS [value]FROM[dbo].[Members] AS [t0].[ID] = #p0
$48.00, 10/20/2005
$44.00, 3/11/2006
My VB Code
Public Class FormPaymentsGroup
Private db As New KarateClassesDataContext
Private Sub FormPaymentsGroup_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.PaymentsTableAdapter.Fill(Me.KarateDataSet.Payments)
'Group payments by Member_ID (FKey) in the Payments table. (Working fine)
Dim IdQuery = From aMember In db.Payments
Group aMember By aMember.Member_Id
Into MemberPayments = Group
For Each memberID In IdQuery
' Use the passed member_Id to target the row in the Members table and return the first_name & last_name.
' PROBLEM: This only seems to be returning the query itself; not the result.
Dim currMemberID = memberID.Member_Id
Dim nameQuery = From aName In db.Members
Where aName.ID = currMemberID
Select aName.First_Name + " " + aName.Last_Name
Dim currName = nameQuery.ToString ' Load the query result into a portable variable.
LbxMemberPayments.Items.Add("Member name = " & currName) ' PROBLEM: This is where the name SHOULD BE posted to the listbox.
' This is bound to the Members table but directs it based on the above IdQuery.
For Each enteredPayment In memberID.MemberPayments
LbxMemberPayments.Items.Add(vbTab & FormatCurrency(enteredPayment.Amount) & ", " & enteredPayment.Payment_Date)
Next
LbxMemberPayments.Items.Add(vbCr) ' Carriage return formatting
Next
End Sub
End Class
change
Dim currName = nameQuery.ToString
to
Dim currName = nameQuery.FirstOrDefault

Display newly created record in Formview

I have this form on VS2012 with asp.net. First I do search for the patron, then go to verify information for that patron. This patron information is displayed in ItemTemplate(ReadOnly). If that is not the patron they are looking for then they can add a new patron with "New button" (asp.net code). I am able to get the id of the new Patron(which is PK). However I am not able to display this newly created record on the form after inserting. It still displays the record which was on display. Since this a formview I did not enable "Paging".
Is it possible to call the pageload event from datasource_inserted event? Then I can pass the new patron ID for display. I declared this ID as global variable?
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim lvPatronID As String
lvPatronID = Request.QueryString("value1")
If lvPatronID = "" Then
frmPatronView.ChangeMode(FormViewMode.Insert)
Else
frmPatronView.ChangeMode(FormViewMode.ReadOnly)
GvPatronID = lvPatronID
lblPatronID.Text = GvPatronID
End If
Protected Sub PatronDS_Inserted(sender As Object, e As SqlDataSourceStatusEventArgs) Handles PatronDS.Inserted
NewID = e.Command.Parameters("#PatronID").Value.ToString
GvPatronID = NewID
End Sub
Well I answered part of my own question. The following change to the Inserted event will let me view the newly inserted data. I have another button to add new record in the emptytemplate of the search form. This is why I am changing the mode to insert as the default mode is readonly. This will let me insert the data but after inserting it doesn't display the form at all. Not sure why Inserted event is not kicking in properly.
Protected Sub PatronDS_Inserted(sender As Object, e As SqlDataSourceStatusEventArgs) Handles PatronDS.Inserted
Dim NewID As String = Nothing
Try
NewID = e.Command.Parameters("#PatronID").Value.ToString
PatronDS.SelectCommand = "SELECT * FROM tblPatron WHERE PatronID='" & NewID & "'"
lblPatronID.Text = NewID.Trim()
frmPatronView.DataBind()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

How to insert a data field into an empty table

I am making a front-end application in VB. The back-end is Oracle. I want an autogenerated ID on the click of a "New" button. It works well if data is present in the table, but shows an error if the table is empty. What do I need to insert so that it works when I am using the application for the first time? My button code is as follows:
Private Sub cmd_new_Click()
Call txt_clear
txt_name.Enabled = True
Set rsCat = New ADODB.Recordset
rsCat.Open "Category", conn, adOpenDynamic, adLockPessimistic
If rsCat.EOF = rscat.BOF Then
tempId = 1000
Else
rsCat.MoveLast
tempId = rsCat.Fields("Category_Id") + 1
End If
txt_Id = tempId
cmd_Save.Enabled = True
cmd_new = False
End Sub
check rscat.RecordCount=-1
Basically, change
If rsCat.EOF = rscat.BOF Then
to
If rsCat.RecordCount=-1 Then

Resources