Home > Mobile >  Temp table has no information but original table does
Temp table has no information but original table does

Time:12-02

I have a datatable that has all the data in it but when my VB.net program runs it and I make a temptable, the temptable has no info. WHat am I doing wrong?

 Public Sub HTSCode()
    Dim TempTable As New DataTable
    Dim DV As DataView

    TempTable = RatesDataSet.HTS
    DV = TempTable.DefaultView
    DV.Sort = "HTS Code NA"
    TempTable = DV.ToTable
    For Each Row As DataRow In TempTable.Rows
        'doesnt get to this point cause there are no rows.
    Next
End Sub

I am attaching pictures 1 of my datatable before I run it so there is info there and the second is when running it shows it empty. I am now even getting the data directly from the table and not a copy of it or temptable anymore. Picture 1 before running while running its empty

CodePudding user response:

The answer is your problem lies elsewhere. Using this sample to simulate your code, I can't ever get an object with no rows

Public Class ds
    Public ReadOnly Property HTS As DataTable
        Get
            Dim dt As New DataTable()
            dt.Columns.AddRange(
                {
                    New DataColumn("HTS Code", GetType(Integer)),
                    New DataColumn("HTS Code NA", GetType(Integer))
                })
            For i = 0 To 4
                Dim row = dt.NewRow()
                row("HTS Code") = i
                row("HTS Code NA") = 10 - i
                dt.Rows.Add(row)
            Next
            Return dt
        End Get
    End Property
End Class
Dim RatesDataSet = New ds

Dim TempTable As DataTable
Dim DV As DataView

TempTable = RatesDataSet.HTS
Console.WriteLine(TempTable.Rows.Count)
DV = TempTable.DefaultView
Console.WriteLine(DV.Count)
DV.Sort = "HTS Code NA"
Console.WriteLine(DV.Count)
TempTable = DV.ToTable
Console.WriteLine(TempTable.Rows.Count)
Console.WriteLine("HTS Code NA:")
For Each Row As DataRow In TempTable.Rows
    Console.WriteLine(Row("HTS Code NA"))
Next

Output

5
5
5
5
HTS Code NA:
6
7
8
9
10

CodePudding user response:

I think it was my dumbness I never linked the table to that form. As soon as I did that the table was filled and works. Sorry and thanks

  • Related