简体   繁体   English

使用oleDBConnection将CSV数据读取到C#数据集中并添加列标题

[英]Reading CSV data with oleDBConnection into a C# DataSet and adding column headings

I have a .csv file that I am reading into C# via an OLEDBConnection. 我有一个.csv文件,正在通过OLEDBConnection读入C#。 I am loading this into a DataSet. 我正在将其加载到数据集中。 This step works fine. 此步骤工作正常。 My data in the .csv file does not have any heading data/column headings. 我的.csv文件中的数据没有任何标题数据/列标题。 I want to add column headings to my DataSet in C# rather than directly into the .csv file. 我想将列标题添加到C#中的DataSet中,而不是直接添加到.csv文件中。 If I try to add column headings, then it just creates a new column on the end of the data, however I want to add the heading to the existing columns that already have data in it rather than create a new column. 如果尝试添加列标题,那么它只是在数据末尾创建了一个新列,但是我想将标题添加到已经有数据的现有列中,而不是创建一个新列。

Just access the column using index and the change the name 只需使用索引访问列并更改名称

DataTable table = your datatable;
table.Columns[0].ColumnName = "Foo";

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

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