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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 12:45:16  来源:igfitidea点击:

Number of columns in dataset

c#.net

提问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 DataTablebefore asking this. As it should work.

DataTable在问这个之前,你应该看看的属性。因为它应该工作。

ds.Tables[0].Columns.Count;

回答by Tim Schmelter

Use the DataTable.Columns.Countproperty. So ds.Tables[0].Columns.Count.

使用DataTable.Columns.Count物业。所以ds.Tables[0].Columns.Count

If you have a DataRowyou can also use this property via...

如果你有一个DataRow你也可以使用这个属性通过...

int columnCount = row.Table.Columns.Count;

or another option is the DataRow.ItemArraywhich contains all fields:

或另一个选项是DataRow.ItemArray包含所有字段的:

int columnCount = row.ItemArray.Length;