如果一列为空,则不添加Dtable.Columns.Add方法 [英] Dtable.Columns.Add method not adding if one column is blank

查看:55
本文介绍了如果一列为空,则不添加Dtable.Columns.Add方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好日子



我遇到了一个问题我正在将列中的值添加到一个名为address的新列中,除非其中没有任何内容它没有添加任何内容的列请在下面找到我的代码和我的数据表示例,你会看到有一个说

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:

没有地址被创建

不应该。



" should not be.

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();







<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

推荐答案

尝试使用IsNull()



例如:

(假设所有列数据类型都是字符串)



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;


这篇关于如果一列为空,则不添加Dtable.Columns.Add方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆