C# 数据集中的列数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18615063/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Number of columns in dataset
提问by steave
Is it possible to find the number of columns a data set has?
是否可以找到数据集的列数?
I know we can find the length of rows with:
我知道我们可以找到行的长度:
ds.Tables[0].Rows.length
Is there something similar for counting or returning the length of the columns?
是否有类似的东西来计算或返回列的长度?
采纳答案by Sachin
You should look the properties of DataTable
before asking this. As it should work.
DataTable
在问这个之前,你应该看看的属性。因为它应该工作。
ds.Tables[0].Columns.Count;
回答by Tim Schmelter
Use the DataTable.Columns.Count
property. So ds.Tables[0].Columns.Count
.
使用DataTable.Columns.Count
物业。所以ds.Tables[0].Columns.Count
。
If you have a DataRow
you can also use this property via...
如果你有一个DataRow
你也可以使用这个属性通过...
int columnCount = row.Table.Columns.Count;
or another option is the DataRow.ItemArray
which contains all fields:
或另一个选项是DataRow.ItemArray
包含所有字段的:
int columnCount = row.ItemArray.Length;