简体   繁体   English

SharePoint 2010列表中具有列名称的空DataTable

[英]An empty DataTable with column names from SharePoint 2010 List

I am developing a project in SharePoint 2010. 我正在SharePoint 2010中开发一个项目。

My requirement is to get an empty DataTable but with column names in it from SharePoint List. 我的要求是获取一个空的DataTable,但要从SharePoint List中获取列名。

The .GetDataTable() method returns only if it has a value. .GetDataTable()方法仅在具有值的情况下返回。

So basically I need a structure of the list in a DataTable. 所以基本上我需要一个DataTable中的列表结构。

This should give you an empty datatable if the GetDataTable does not retrieve column information. 如果GetDataTable不检索列信息,则应该为您提供一个空的数据表。

DataTable _dt = new DataTable();

foreach (SPField spf in _lst.Fields)
{
   _dt.Columns.Add(spf.InternalName.ToString(), spf.Type.GetType());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM