如何在数据集中获取最小和最大列数? [英] How to get min and max columns count in dataset?

查看:66
本文介绍了如何在数据集中获取最小和最大列数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在datatable中添加了两个新列,并在这两列中打印了datatable列的最大和最小数量。如何做。我将尝试下面的代码。



我尝试了什么:



I had add two new column to datatable and print the maximum and minimum count of datatable column in this two columns how to do.i will try the below code.

What I have tried:

ds.Tables[k].Columns.Add("Column52");
ds.Tables["Source" + c].AcceptChanges();
for (int f = 0; f < ds.Tables[k].Rows.Count; f++)
{
ds.Tables[k].Rows[f]["Column52"] =ds.Tables[k].Compute("MAX(Column52)","");
//double maxval = Convert.ToDouble((ds.Tables[k].Compute("MAX(Column52)", "")));
}





i试图添加新列并获取最大列数但是

对象无法从DBNull转换为其他类型。

发生异常错误。



i have tried to add new column and get maximum column count but
Object cannot be cast from DBNull to other types.
Exception error occur.

推荐答案

这里有两个问题:第一个问题是,正如Karthik Bangalore所说,这将显示新列的所有行中的最大值,您说这是你不想要的。但这就是计算列的作用:在每一行中显示一个值。所以,如果这不是你想要的,那么你需要重新思考你正在做的事情,并且可能完全找到另一种方式 - 这不涉及新专栏!



另一个是Column52的数据是一个NULLable列,并且您正在尝试将NULL值转换为double值,这在DBNull传播数据以产生NULL结果时不起作用。检查您的数据:为什么您想要成为数字的列中有NULL值?
There are two problems here: the first is that as Karthik Bangalore says, that will show the Maximum value in all rows of the new column, which you say you don't want. But that's what a computed column will do: show a value in every row. So if that isn't what you want, then you need to rethink what you are doing and probably find another way altogether - that doesn't involve a new column!

The other is that your data for "Column52" is a NULLable column, and you are trying to convert NULL values to a double value, which won't work as DBNull propagates through data to produce a NULL result. Check your data: why have you got NULL values in a column you want to be numeric?


这篇关于如何在数据集中获取最小和最大列数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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