-
July 9th, 2010, 09:14 AM
#1
[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?
I'm using .NET Framework 3.5
I'm planning to be spontaneous tomorrow
-
July 9th, 2010, 12:26 PM
#2
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)
-
July 12th, 2010, 06:30 AM
#3
Re: Datatable - creating new columns ignores datatype?
Thank you so much, problem solved
I'm using .NET Framework 3.5
I'm planning to be spontaneous tomorrow
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|