[RESOLVED] Datatable - creating new columns ignores datatype?
I have a datatable which has a number of rows containing data
Then I need to add some empty datacolumns which I do like this:
Code:
Dim OT_Hours As New DataColumn("OT_Hours")
OT_Hours.DataType = System.Type.GetType("System.Double")
OT_Hours.DefaultValue = 0
MyTable.Columns.Add("OT_Hours")
When I come to use the datatable I find that these new columns now have datatype String and initial values of ""
I tested this using:
Code:
For Each column As DataColumn In MyTable.Columns
Console.WriteLine(column.ColumnName & " is a " & Type.GetTypeCode(column.DataType).ToString)
Next
I need to use these columns for calculations
any ideas?
What am I doing wrong?
Re: Datatable - creating new columns ignores datatype?
When you add "OT_Hours" you are creating a new column with that name not using the OT_Hours you created earlier. You need to:
MyTable.Columns.Add(OT_Hours)
Re: Datatable - creating new columns ignores datatype?
Thank you so much, problem solved