Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day everybody

I am stuck with an issue i am adding values from columns into a new column called address this works fine unless there is nothing in one of the columns the it doesn't add anything at all please find my code below and an example of my data table you will see there is one that says "
Quote:
no address get created
" should not be.

SQL
Dtable.Columns.Add("Address", typeof(string), "ZoneID +','+ Suburb + ','+ PostalCode + ',' + Area").AllowDBNull = true;
            Dtable.Columns.Add("Value", typeof(string), "Suburb + '  '+ PostalCode").AllowDBNull = true;
            Select1.DataSource = Dtable;
            Select1.DataTextField = "Value";
            Select1.DataValueField = "Address";
            Select1.DataBind();


HTML
<table>
<tr>
<td>ZoneID</td>
<td>Suburb</td>
<td>Area</td>
<td>PostalCode</td>
<td>Address</td>
<td>Value</td>
</tr>
<tr>
<td>ZISA106313473401</td>
<td>PIETERSBURG</td>
<td>NULL</td>
<td>700</td>
<td>no address get created</td>
<td>PIETERSBURG  700</td>
</tr>
<tr>
<td>ZISA106313473501</td>
<td>PIETERSBURG EXT 29</td>
<td>PIETERSBURG</td>
<td>699</td>
<td>ZISA106313473501,PIETERSBURG EXT 29,699,PIETERSBURG</td>
<td>PIETERSBURG EXT 29  699</td>
</tr>
</table>

any suggestions would be appreciated
Posted

1 solution

Try to use IsNull()

For Example:
(Assuming all columns datatype is string)

Dtable.Columns.Add("Address", typeof(string), "ISNULL(ZoneID,'') +','+ ISNULL(Suburb,'') + ','+ ISNULL(PostalCode,'') + ',' + ISNULL(Area,'')").AllowDBNull = true;
 
Share this answer
 
v2
Comments
mrDivan 30-Sep-14 3:38am    
Thank you so much it worked I really appreciate it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900