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

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...
 
M

Marina

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top