joining three strings where one is null?

V

VMI

In my datatable, I'm retrieving three fields from an Access table and I
concatenate them into one string. Then I put this information in another
datacolumn that I added to the datatable (with DataColumn.Expression).
Unfortunately, when one's a Null, apparently it makes the whole string a
Null and that's what's seen in the grid.
This is what I use:

DataColumn col_input = new DataColumn("Input");
col_input.DataType = System.Type.GetType("System.String");
col_input.Expression = "InFBU + ' \r\n' + InDel + '\r\n' + InCity + ' '" +
"+ InState + ' ' + InZIP + '-' + InAddon";

But in most cases, InAddon will be null so, when I display col_input in my
grid, it only displays the value null.
What can I do to avoid this?
 
N

Nicholas Paldino [.NET/C# MVP]

VMI,

You want to use the ISNULL expression, like so:

col_input.Expression = "ISNULL(InFBU, '') + ' \r\n' + ISNULL(InDel, '') +
'\r\n' + ISNULL(InCity, '') + ' '" + "+ ISNULL(InState, '') + ' ' +
ISNULL(InZIP, '') + '-' + ISNULL(InAddon, '')";

Hope this helps.
 
V

VMI

It worked great.

Thanks again.


Nicholas Paldino said:
VMI,

You want to use the ISNULL expression, like so:

col_input.Expression = "ISNULL(InFBU, '') + ' \r\n' + ISNULL(InDel, '') +
'\r\n' + ISNULL(InCity, '') + ' '" + "+ ISNULL(InState, '') + ' ' +
ISNULL(InZIP, '') + '-' + ISNULL(InAddon, '')";

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

VMI said:
In my datatable, I'm retrieving three fields from an Access table and I
concatenate them into one string. Then I put this information in another
datacolumn that I added to the datatable (with DataColumn.Expression).
Unfortunately, when one's a Null, apparently it makes the whole string a
Null and that's what's seen in the grid.
This is what I use:

DataColumn col_input = new DataColumn("Input");
col_input.DataType = System.Type.GetType("System.String");
col_input.Expression = "InFBU + ' \r\n' + InDel + '\r\n' + InCity + ' '"
+
"+ InState + ' ' + InZIP + '-' + InAddon";

But in most cases, InAddon will be null so, when I display col_input in
my grid, it only displays the value null.
What can I do to avoid this?
 

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