如何将零值替换为数据集中的空值 [英] How to Replace Zero values to Null Values in Dataset

查看:160
本文介绍了如何将零值替换为数据集中的空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

在这里我想从数据集中将零值替换为Null Vlaues.实际上我的问题是iam将此数据集值插入到aspx饼图中.虽然iam将数据集绑定到零值也在该节点上显示的那个图表,所以我不想显示该Chart中的零值.因此,我想将零值替换为Null并将数据集绑定到aspx chart.so,如果有任何信息,请与我分享.


问候,

AnilKumar.D

Dear Friends,

Here i want to Replace Zero values to Null Vlaues from Dataset.Actually My Problem is iam Inserting this dataset values to aspx pie chart.While iam binding the dataset to that Chart that Zero values also Displaying in that Nodes.So I dont want to show that Zero values in that Chart.So i want to Replace the Zero values to Null and bind the dataset to aspx chart.so if any information please share with me.


Regards,

AnilKumar.D

推荐答案



构造一个for循环以迭代datatable/dataview中的行,并检查在特定列中是否具有0(如果这样),请为其分配DBNull.

问候
Menaka
Hi,

Construct a for loop to iterate the rows in the datatable/dataview and check if it having 0 in the specific column if so assign DBNull to it.

Regards
Menaka


foreach (DataRow dr in ds.Table[0].Rows)
{
if(dr["ColumnName"]==0)
{
dr["ColumnName"] = null;
}
}


尝试一下:
假设您的数据表是dt
try this:
assuming your datatable is dt
dt=(dt.AsEnumerable().Select(delegate(DataRow r)
{

    DataRow nr = dt.NewRow();

    foreach (DataColumn item in dt.Columns)

    {

        nr.SetField(item.ColumnName, r[item.ColumnName].ToString() =="0"  ? null : r[item.ColumnName]);

    }

    return nr;

})).CopyToDataTable();


这篇关于如何将零值替换为数据集中的空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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