469,951 Members | 2,336 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,951 developers. It's quick & easy.

Add a new DataTable column with type "Integer"?

I have a dataview, and I am trying to "clone" its structure only in part, by creating a new table via code. I cut out most of the columns, so this is easier to read. My question is - Why does this always seem to add things a a string?

Later in my code, I try to sort based on "View_Order", but it acts like a string. The values sort as 1,2,20,21,22,3,4, NOT 1,2,3,4,20,21,22 like it should.

Using Cint() while moving the values from table to table didn't work for me... and the boolean becomes text as well. Is the problem in this code, or would it be elsewhere?

Expand|Select|Wrap|Line Numbers
  1.     Private Function ConvertTable(ByVal ds As DataSet, ByVal TableName As String, Byval WHEREexpression As String, Byval  SORTexpression As String) As DataTable
  2.         'For Schedule Tasks, convert all "dates+times" to "dates only" as strings
  4.         Dim dv As DataView = GetViewTable(ds.Tables(TableName), WHEREexppression, SORTexpression)
  5.         Dim dt As New DataTable
  7.         dt.Columns.Add(New DataColumn("Task", GetType(String)))
  8.         dt.Columns.Add(New DataColumn("View_Order", System.Type.GetType("System.Int64")))
  9.         dt.Columns.Add(New DataColumn("Completed", GetType(Boolean)))
  11.         For i = 0 To dv.Table.Rows.Count - 1
  12.             dt.Rows.Add()
  14.             dt.Rows(i).Item("Task") = dv.Table.Rows(i).Item("Task").ToString
  16.             dt.Rows(i).Item("View_Order") = CInt(dv.Table.Rows(i).Item("View_Order").ToString)
  17.             Try
  18.                 dt.Rows(i).Item("Completed") = dv.Table.Rows(i).Item("Completed")
  19.             Catch ex As Exception
  20.             End Try
  21.         Next i
  23.         Return dt
  24.     End Function
Feb 27 '09 #1
1 23187
Nevermind... I found the solution. The problem was that eveything had already been converted to strings before I ran the function.
Mar 2 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Igor Shevchenko | last post: by
6 posts views Thread by **Developer** | last post: by
11 posts views Thread by Ron L | last post: by
12 posts views Thread by Prabu Subroto | last post: by
9 posts views Thread by coaxfiber | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.