The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Gilbert Tordeur (7) [Avatar] Offline
#1
Hello.
Context : VB 2008, Webforms, SQL Server 2000
I use a Linq query as DataSource for a Lisbox :

Dim ContexteFluide As New FluideDataContext(cnString)
Dim LesClients = From Client In ContexteFluide.Client _
Where Client.FclCodSociete = numSocieteJcEnFrance
Select Case codTypeCritere
Case EjcCodTypeCritereRecherche.AucunCritere
Case EjcCodTypeCritereRecherche.CritereCommencePar
LesClients = From Client In LesClients _
Where Client.FclNom.StartsWith(valeurCritere)
Case EjcCodTypeCritereRecherche.CritereContient
LesClients = From Client In LesClients _
Where Client.FclNom.Contains(valeurCritere)
End Select
Dim MesClients = From Client In LesClients _
Order By Client.FclNom, Client.FclLocalite, Client.FclRue1 _
Select Client.FclCodClient, FclNomLocaliteRue = Client.FclNom &
" - " & Client.FclLocalite & " - " & Client.FclRue1

lbx.DataTextField = "FclNomLocaliteRue"
lbx.DataValueField = "FclCodClient"
lbx.DataSource = MesClients
lbx.DataBind()

My problem is the following : if the field FclRue1 is NULL, then all
FclNomLocaliteRue is displayed as space, instead of display
Client.FclNom & " - " & Client.FclLocalite & " - "

How can I fix this ?

Thank you in advance,
Gilbert
jwooley (123) [Avatar] Offline
#2
Re: Linq query and concatenation with NULL
Try using the new Ternary If operator in VB:


Select Client.FclCodClient, FclNomLocaliteRue = Client.FclNom &
" - " & Client.FclLocalite & " - " & If(Client.FclRue1,"")
Jim
Gilbert Tordeur (7) [Avatar] Offline
#3
Re: Linq query and concatenation with NULL
Wonderful Jim. It works fine !
Where can I read any doc about the "ternary If" ?

Thank you,
Gilbert
jwooley (123) [Avatar] Offline
#4
Re: Linq query and concatenation with NULL
The help documentation is pretty good. See the following (in VS2008 help)

ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/dv_vbalr/html/dd56c9df-7cd4-442c-9ba6-20c70ee44c8f.htm

Jim
Gilbert Tordeur (7) [Avatar] Offline
#5
Re: Linq query and concatenation with NULL
OK. I got it.
Thank you,
Gilbert