如何在Sqlserver中获取单元格值的列名? [英] How Can I Get The Columnname Of Cell Value In Sqlserver?

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

问题描述

如何从SqlServer获取DataTable的特定单元格的列名。

我自己解释:

i有一个单元格的值,我想得到一个此值的列名。所以我知道:reader.GetName()给我一个列的名称和reader [columnname]。ToString()给出Cell的值。假设我只有一个单元格值,并且我搜索此单元格的columName,如何获取此单元格的columnName值? readerName of reader [columnname]。ToString()?任何好方法都会受到欢迎。

感谢您的帮助。

how can i get a columnname of a specific cell of DataTable from SqlServer.
I explane myself:
i have a value of a cell and i want to get a columnname of this value. So i know that: "reader.GetName()" give me the Name of a column and "reader["columnname"].ToString()" give the value of the Cell. supposed i only have a cell value ,and i search the columName of this Cell, how can i get the columnName of this cell Value? "ColumnName of reader["columnname"].ToString()" ? any good way will be welcome.
Thanks for your Help.

推荐答案

查看DataTable.Columns集合。集合中的每个DataColumn都有一个ColumnName属性,它应该是你要找的。



如果你试图从特定单元格的值中找到它,那么您将使用嵌套的for循环来按索引号检查每个Row的每个Cell,当您找到具有适当值的单元格时,您可以使用列索引直接从列访问列名称[index] .ColumnName property。
Look at the DataTable.Columns collection. Each DataColumn in the collection has a ColumnName property which should be what you are looking for.

If you are trying to find this from a value of a particular cell, then you will have use a nested for loop to check each Cell of each Row by index number, and when you find a cell with the appropriate value you can use the column index to access the column name directly from the Columns[index].ColumnName property.


你已经在如何从Sqlserver获取Colum名称? [ ^ ]。请不要重新发布,编辑原文。
You already posted this question at How Can I Get Colum Name From Sqlserver?[^]. Please do not repost, edit your original.


这篇关于如何在Sqlserver中获取单元格值的列名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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