This is a simplifed verson of my code
Dim dt As New DataTable()`
dt.Columns.Add(New DataColumn("Year 0 ")
dt.Columns.Add(New DataColumn("Year 1")
dt.Columns.Add(New DataColumn("Year 2 ")
dt.Columns.Add(New DataColumn("Year 3")
dt.Columns.Add(New DataColumn("Year 4 ")
dt.Columns.Add(New DataColumn("Year 5")
dt.Columns.Add(New DataColumn("Total")
dt.Rows.Add("Net Economic Benefit")
Which creates a table like this (ignore the other rows)
My question is, is there a way for me to add to the row "Net Economic Benefit" ? The code should basically do what the following code does
dt.Rows.Add("Net Economic Benefit", "1", "2", "3")
Except I was to create a loop to add the "1", "2", "3" so I cannot use that code as it will create multiple rows. Code might look something like:
dt.Rows.Add("Net Economic Benefit")
dt.Rows("Net Economic Benefit").AddRow("1")
Basically it refers to the already added row "Net Economic Benefit" and then it adds the "1", "2", and "3"
CodePudding user response:
Once you have an existing DataRow
, however you may have created it, you set the fields by indexing the row, either by column name or ordinal:
Dim row As DataRow
'...
row("SomeColumn") = someValue
row(index) = someOtherValue