By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,058 Members | 1,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,058 IT Pros & Developers. It's quick & easy.

joining three strings where one is null?

P: n/a
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?
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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]
- mv*@spam.guard.caspershouse.com

"VMI" <vo******@yahoo.com> wrote in message
news:eA**************@TK2MSFTNGP09.phx.gbl...
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?

Nov 16 '05 #2

P: n/a
VMI
It worked great.

Thanks again.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eF**************@TK2MSFTNGP11.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"VMI" <vo******@yahoo.com> wrote in message
news:eA**************@TK2MSFTNGP09.phx.gbl...
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?


Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.