Adding a Calculated column to a DataTable: How to handle w/ null values

  • Thread starter Thread starter Sam
  • Start date Start date
S

Sam

I have a DataTable w/ FirstName, MiddleName, and LastName.

I want to add a column called "FullName" as so:

***********************************************************************
Dim dt As DataTable
Dim sExp As String

sExp= "trim(FirstName) + trim(' ' + MiddleName) + ' ' + trim(LastName)"
dt.Columns.Add("FullName", GetType(String), sExp)
***********************************************************************

MiddleName can be null, and if it is, then a null is returned for the expression.

Is there a way around it?

Thanks...
 
Yes, change the expression to be:
sExp= "trim(FirstName) + IsNull(trim(' ' + MiddleName),'') + ' ' +
trim(LastName)"
 
Back
Top