473,395 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Add a new DataTable column with type "Integer"?

36
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.  
Feb 27 '09 #1
1 24422
Infog
36
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

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

Similar topics

2
by: Igor Shevchenko | last post by:
Hi, Are there any plans on adding CLUSTER-related information to "\d tablename" ? -- Best regards, Igor Shevchenko ---------------------------(end of broadcast)---------------------------...
4
by: Supra | last post by:
value of type "Integer" cannot be convert to system.color Public Sub APIHighlight2(ByVal BgColour As Integer, ByVal FgColour As Integer) SelectionHighlightBackColour(BgColour) Dim rtb As New...
2
by: Supra | last post by:
value of type "Integer" cannot be convert to system.color. in procedure events: Function doColor(ByVal rtb As RichTextBox, ByVal a As String) Dim bColor, fColor, fgcolor, bgcolor As Integer .....
6
by: **Developer** | last post by:
Notice below I sometimes used the "A" version. I found by cut-and-try that only the "A" version would work correctly. Anyone have a suggestion of why the "W" version would not work correctly? ...
11
by: Ron L | last post by:
I have a data table that lists a series of items in my database. In my user form, I want the user to be able to filter by a number of criteria (e.g. location, contract, date modified, etc). Other...
2
by: Zygo Blaxell | last post by:
I have a table with a few million rows of temperature data keyed by timestamp. I want to group these rows by timestamp intervals (e.g. every 32 seconds), compute aggregate functions on the...
12
by: Prabu Subroto | last post by:
Dear my friends... I am using postgres 7.4 and SuSE 9.1. I want to use auto_increment as on MySQL. I look up the documentation on www.postgres.com and I found "serial" . But I don't know...
6
by: Ying Lu | last post by:
Hi, I have a question about alter a column's type in a postgreSQL table. For example, I have 10, 000 records in a table name "test", I'd like to change column "machineID" type from integer to...
9
by: coaxfiber | last post by:
why is it that when i used the value with zero,comparing two integers,it seems that i got the wrong ouput? Please consider the ff: #!/bin/ksh echo "63918000009" > k cat k read x < k ((...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.