0

I have a DataTable read from a csv file:

ID,ItemCode,ItemDescription
1,Test0,test item
2,Test2,second test item

When I try to create an additional column as in https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/dataset-datatable-dataview/adding-columns-to-a-datatable, it silently fails. The code:

dataTable.TableName = "test"
dataTable.Columns.Add("MyTestColumn", GetType(String))
dataTable.AcceptChanges()
Using sw As StringWriter = New StringWriter()
    dataTable.WriteXml(sw)
    Console.WriteLine(sw)
End Using

has output

<DocumentElement>
  <test>
    <Column1>ID</Column1>
    <Column2>ItemCode</Column2>
    <Column3>ItemDescription</Column3>
  </test>
  <test>
    <Column1>1</Column1>
    <Column2>Test0</Column2>
    <Column3>test item</Column3>
  </test>
  <test>
    <Column1>2</Column1>
    <Column2>Test2</Column2>
    <Column3>second test item</Column3>
  </test>
</DocumentElement>

Is it possible to add a column in this way?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.