DataColumn的防爆pression到Concat的列 - 将空 [英] DataColumn Expression to concat columns - Returning Empty

查看:94
本文介绍了DataColumn的防爆pression到Concat的列 - 将空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataTable,并有两列名字和姓氏。

I've a DataTable and have two columns 'FirstName' and 'LastName'.

我创建的DataColumn从这两列Concat的价值。这里是我的code -

I've created a datacolumn to concat value from these two columns. Here is my code -

DataColumn fullname = dt.Columns.Add("Full Name");
string fn = string.Format(string.Concat("'First Name - '+", "{0}", "+ ';<br />"), "FN");
string ln = string.Format(string.Concat("Last Name - '+", "{0}", "+ ';<br />"), "LN");
otherDetails.Expression = string.Concat(fn, ln);

在code是两个领域工作的罚款,并会连接值。但是,如果任何列值是null,则除权pression不能正常工作,并返回为空。

The code is working fine and concatenates values from two fields. But if any of the column value is null then the expression is not working and is returning as empty.

例如对于第五记录,如果名字是添和第二个名字为null,我想显示为'添'的值。而是为记录这个前pression列的值是空的。

For example for the 5th record is if first name is 'Tim' and the second name is null the I want the value to be displayed as 'Tim'. But instead for that record the value of this expression column is empty.

任何想法?

推荐答案

你觉得你可以尝试

string fn = string.Format(string.Concat("'First Name - '+", "{0}", "+ ';<br />"), "IsNull(FN, '')");
string ln = string.Format(string.Concat("Last Name - '+", "{0}", "+ ';<br />"), "IsNull(LN, '')";

这篇关于DataColumn的防爆pression到Concat的列 - 将空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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