如何获取数据集的字段名称 [英] How to get field names of a dataset

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

问题描述

我的数据集如下:



I have a data set as follows:

namespace user_control_typed_dataset
{


   partial class Studentdataset
   {

        public string Name{get;set;}
        public string ID { get; set; }
        public string Address { get; set;}

        private void InitializeComponent()
        {


        }

    }
}





i想要打印字段名称Name,ID和Address.But当我使用字段信息属性时,我也得到了很多其他字段和名称,我得到< name> backing_field.But我只想要名字。如何解决这个问题。请帮助我。



i want to print the field names Name,ID and Address.But when i'm using field info property,i'm getting so many other field too and intead of Name ,i'm getting <name> backing_field.But i want Name only.How to solve this.Pls help me.

推荐答案

这是一个小例子给你



DataTable table = new DataTable();

table.Columns.Add(Employee,typeof(string));

table.Columns .Add(ID,typeof(string));



table.Rows.Add(Xing Zuber,1);

table.Rows.Add(Daving solman,2);

table.Rows.Add(Iyan Yokovich,3);

table.Rows.Add(Dev richardson,4);

table.Rows.Add(Jeanson,5);



string [] columnNames = table.Columns.Cast< datacolumn>()

.Select(x => x.ColumnName)

.ToArray();





foreach(stringNames中的字符串dc)

{

string st = dc.ToString();

}
Here is a small example for you

DataTable table = new DataTable();
table.Columns.Add("Employee", typeof(string));
table.Columns.Add("ID", typeof(string));

table.Rows.Add("Xing Zuber", "1");
table.Rows.Add("Daving solman", "2");
table.Rows.Add("Iyan Yokovich", "3");
table.Rows.Add("Dev richardson", "4");
table.Rows.Add("Jeanson ", "5");

string[] columnNames = table.Columns.Cast<datacolumn>()
.Select(x => x.ColumnName)
.ToArray();


foreach (string dc in columnNames)
{
string st = dc.ToString();
}


Studentdataset student = new Studentdataset();
studentProperties = student.GetType().GetProperties();
foreach (var propertyInfo in studentProperties)
{
  Consol.WriteLine(propertyInfo.Name);
}


这篇关于如何获取数据集的字段名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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