Search code examples
vb.netdatatable

Both the Row Number and Field Value Appear in Cell Values Pulled from DataTable


I filled a DataTable (dt) with values from several text and double fields using various data sources (Excel, Access, etc.). I then populated a DataGridView from dt, and the text, integer, and real (double) columns are visible in the DataGridView and don't have any issues.

However, in one area of my code I am fetching age values (column 6) of specific cells using the code

Dim myage As Integer = dt.rows(i)(j) 

The value of age in row 0 is 19, so when using myage = dt.rows(0)(6) on most occasions the age appears as 19. However, in another area of my application (using the same dt and code to fetch age values) the age appears as 0 19, where 0 is the row number of dt. If I get the row 1 value for age using dt.rows(1)(6) it shows as 1 24.

Why is the dt yielding only a numeric value in one area of my application, and yielding the row and the age in another area of my application?

I am not sure if use of .row is the issue, and I already tried dt.rows(1).Field(Of Integer)(6) and it doesn't prevent the row number from appearing.

Since I need to pull cell values from dt in numerous places in my app, how can I avoid this dilemma?


Solution

  • While adding datatable column change your datatype to integer for ex : dt.Columns.Add("Age", System.Type.GetType("System.Int32")) then try it will support.