06-01-20 05:52 AM
Answered! Go to Answer.
06-01-20 12:55 PM
For Each C As DataColumn In Main_Collection.Columns Dim NewName As String = Cstr(New_Headers.Rows(0)(C.ColumnName)) If String.IsNullOrEmpty(NewName) Then Throw New ApplicationException("Blank field names are not acceptable") Else C.ColumnName = Trim(NewName) End If Next
The loop starts through each column in the Main_Collection. When it starts, it'll have one of the columns, and it starts by creating a variable 'NewName' to hold the new column name temporarily. The Cstr part looks a little confusing. If I explain this wrong, I'm trusting that someone more knowledgeable will correct me. But as I read it, inside the Cstr() parentheses, it is getting the name of the column that has just been retrieved by looping into the column names. the New_Headers.Rows(0) (C.ColumnName) part is getting the ColumnName from the first row (index 0) specifically from the column that has been chosen by the For Each C As DataColumn part of the loop declaration. After that, it just renames C.ColumnName with NewName.
Not sure if I was confusing there, but if you struggled with the same part I did, it was likely the 2-dimensional array/collection part where it does like Rows(0) (C.ColumnName). The (0) part of it is for the rows, and the C part is for the columns. By doing it like that, the code ensures it doesn't matter whether the order of the columns is the same or not.
06-01-20 12:55 PM
For Each C As DataColumn In Main_Collection.Columns Dim NewName As String = Cstr(New_Headers.Rows(0)(C.ColumnName)) If String.IsNullOrEmpty(NewName) Then Throw New ApplicationException("Blank field names are not acceptable") Else C.ColumnName = Trim(NewName) End If Next
The loop starts through each column in the Main_Collection. When it starts, it'll have one of the columns, and it starts by creating a variable 'NewName' to hold the new column name temporarily. The Cstr part looks a little confusing. If I explain this wrong, I'm trusting that someone more knowledgeable will correct me. But as I read it, inside the Cstr() parentheses, it is getting the name of the column that has just been retrieved by looping into the column names. the New_Headers.Rows(0) (C.ColumnName) part is getting the ColumnName from the first row (index 0) specifically from the column that has been chosen by the For Each C As DataColumn part of the loop declaration. After that, it just renames C.ColumnName with NewName.
Not sure if I was confusing there, but if you struggled with the same part I did, it was likely the 2-dimensional array/collection part where it does like Rows(0) (C.ColumnName). The (0) part of it is for the rows, and the C part is for the columns. By doing it like that, the code ensures it doesn't matter whether the order of the columns is the same or not.
07-01-20 12:22 AM