Connecting Tech Pros Worldwide Forums | Help | Site Map

Add a new DataTable column with type "Integer"?

Member
 
Join Date: Dec 2008
Location: Riverside, CA
Posts: 32
#1: Feb 27 '09
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
  3.  
  4.         Dim dv As DataView = GetViewTable(ds.Tables(TableName), WHEREexppression, SORTexpression)
  5.         Dim dt As New DataTable
  6.  
  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)))
  10.  
  11.         For i = 0 To dv.Table.Rows.Count - 1
  12.             dt.Rows.Add()
  13.  
  14.             dt.Rows(i).Item("Task") = dv.Table.Rows(i).Item("Task").ToString
  15.  
  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
  22.  
  23.         Return dt
  24.     End Function
  25.  

Member
 
Join Date: Dec 2008
Location: Riverside, CA
Posts: 32
#2: Mar 2 '09

re: Add a new DataTable column with type "Integer"?


Nevermind... I found the solution. The problem was that eveything had already been converted to strings before I ran the function.
Reply

Tags
add, column, datatable, integer


Similar Visual Basic .NET bytes