[RESOLVED] Create and Fill New Column
I need some helping filling a New Column with values
I am using the following to strip out unwanted string in a string and i want to fill newly created column with split value. I dont know how to get the "Cityrev" into a column value
Code:
With dtlist
Dim dtrow As DataRow
For Each dtrow In dtlist.Rows()
Dim City As String = dtrow.Item("City").ToString()
Dim Cityrev() As String = City.Split(New [Char]() {"("c}, System.StringSplitOptions.None)
Dim revCity As String = Cityrev(Cityrev.Length - 2)
Next
.Columns.Add("Cityrev")
For Each dtrow In dtlist.Rows
dtrow("Cityrev") = dtrow("City")
Next dtrow
End With
Re: Create and Fill New Column
There's not much point processing the data before you've got anywhere to put it. If you read what I posted in your other thread you'll see that I said to add the new column first. You can then loop through the rows and, for each row, get the data from the source column, process it and then put the result into the destination column. You've got all the pieces there. You just need to arrange them into the proper order.
Whenever you write code, the code you write must implement the steps you should already know that your app needs to perform. If you try to write the code first, the likelihood that it will do what you want is low, because you don;t even know what you want yourself.
Re: Create and Fill New Column
Quote:
Originally Posted by
jmcilhinney
There's not much point processing the data before you've got anywhere to put it. If you read what I posted in your other thread you'll see that I said to add the new column first. You can then loop through the rows and, for each row, get the data from the source column, process it and then put the result into the destination column. You've got all the pieces there. You just need to arrange them into the proper order.
Whenever you write code, the code you write must implement the steps you should already know that your app needs to perform. If you try to write the code first, the likelihood that it will do what you want is low, because you don;t even know what you want yourself.
Thanks I understand what your saying but getting the data from the source is what I am not able to see
HTML Code:
With dtlist
.Columns.Add("Cityrev")
Dim dtrow As DataRow
For Each dtrow In dtlist.Rows()
Dim City As String = dtrow.Item("City").ToString()
Dim Cityrev() As String = City.Split(New [Char]() {"("c}, System.StringSplitOptions.None)
Dim revCity As String = Cityrev(Cityrev.Length - 2)
dtrow("Cityrev") = dtrow("City")
Next dtrow
End With
Re: Create and Fill New Column
Again, what did I say to do? Get the data from the original column, process it and put THE RESULT into the new column. What are you doing there? You are getting the data from the original column:
Code:
Dim City As String = dtrow.Item("City").ToString()
You are processing the data:
Code:
Dim Cityrev() As String = City.Split(New [Char]() {"("c}, System.StringSplitOptions.None)
Dim revCity As String = Cityrev(Cityrev.Length - 2)
Finally you are putting THE ORIGINAL DATA into the new column:
Code:
dtrow("Cityrev") = dtrow("City")
What's the point of processing the data if you're not going to use the result of that processing? Put the the result of the processing into the new column, NOT the original data.
Re: Create and Fill New Column
Quote:
Originally Posted by
jmcilhinney
Again, what did I say to do? Get the data from the original column, process it and put
THE RESULT into the new column. What are you doing there? You are getting the data from the original column:
Code:
Dim City As String = dtrow.Item("City").ToString()
You are processing the data:
Code:
Dim Cityrev() As String = City.Split(New [Char]() {"("c}, System.StringSplitOptions.None)
Dim revCity As String = Cityrev(Cityrev.Length - 2)
Finally you are putting
THE ORIGINAL DATA into the new column:
Code:
dtrow("Cityrev") = dtrow("City")
What's the point of processing the data if you're not going to use the result of that processing? Put the the result of the processing into the new column, NOT the original data.
I understand that, my question is HOW do I put the result into the new column
dtrow("Cityrev") = dtrow("revCity")
gives me an error "revCity" does not belong to the datatable
figured it out
dtrow("Cityrev") = revCity