Insert column

  • Thread starter Thread starter Jaga
  • Start date Start date
J

Jaga

Hi

Can I insert a new column into a DataTable after it is filled with data?
I'd like to insert at an index and not to the end of the columns collection.

Thanks in advance

Jaga
 
Hi,

Yes, you can insert new column after dataTable populated, but you cannot
insert it to the specific position. I do not think it should be an issue,
since if you reference to the columns in your code by index, then you could
be in a trouble. Best way to reference them by name and in this case it does
not matter what is the actual index position of the DataColumn - it always
will work properly
Following is an example from MSDN how to add column to the dataTable


Private Sub AddColumn()
Dim cols As DataColumnCollection
Dim myCol As DataColumn
' Get the DataColumnCollection of a table in a DataSet.
cols = DataSet1.Tables("Orders").Columns
' Add a new column and return it.
myCol = cols.Add("Total", System.Type.GetType("System.Decimal"), _
"Price + Tax")
myCol.ReadOnly = True
myCol.Unique = False
End Sub
 
Well, I was answering only to the first part of your question.
The second is, like Val said, you can't place the column at specified
position and you don't need to. :-)

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Miha Markic said:
Hi Jaga,

Yes, you can.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Jaga said:
Hi

Can I insert a new column into a DataTable after it is filled with data?
I'd like to insert at an index and not to the end of the columns collection.

Thanks in advance

Jaga
 
Back
Top