A
Al Repasky
I get this error with the code below. I think it is the line that
strExp is declared. I have tried the ID and not the tYear column and
still get the error.
All I want to do is sort the years.
Thanks,
ripripal
Private Function GetYears()
Dim myRow, dr As DataRow
Dim str As String
Dim i, ib, ie, icnt As Integer
Dim myDataTable As New DataTable
'Declare DataColumn ID
Dim myColumn1 As New DataColumn("ID")
myColumn1.DataType = System.Type.GetType("System.Int32")
'Add Column to table
myDataTable.Columns.Add(myColumn1)
'Declare DataColumn tYear
Dim myColumn2 As New DataColumn("tYear")
myColumn2.DataType = System.Type.GetType("System.Int32")
'Add Column to table
myDataTable.Columns.Add(myColumn2)
'Get rid of duplicates
Dim myUC As New UniqueConstraint("UC",
myDataTable.Columns("tYear"))
myDataTable.Constraints.Add(myUC)
icnt = 0
For Each dr In dsAutos.Tables("tAutos").Rows
icnt = icnt + 1
ib = Val(dr("tBYr"))
i = ib
ie = Val(dr("tEYr"))
Do Until i = ie + 1
Try
myRow = myDataTable.NewRow()
myRow("ID") = icnt
myRow("tYear") = i
Console.WriteLine(myRow("tYear"))
myDataTable.Rows.Add(myRow)
'Me.ListBoxYear.Items.Add(CStr(i))
i = i + 1
Catch
i = i + 1
End Try
Loop
Next
Console.WriteLine(icnt)
Console.WriteLine("-----")
For Each dr In myDataTable.Rows
Console.WriteLine(dr("tYear"))
Next
Dim strExp, strSort As String
'Sort
strExp = "tYear > 1900"
strSort = "tYear"
'Use the Select method to find all rows matching the filter.
Dim drsort As DataRow() = myDataTable.Select(strExp, strSort,
DataViewRowState.Added)
For Each drsort In myDataTable.Rows
Console.WriteLine(drsort("tYear"))
Next
End Function
strExp is declared. I have tried the ID and not the tYear column and
still get the error.
All I want to do is sort the years.
Thanks,
ripripal
Private Function GetYears()
Dim myRow, dr As DataRow
Dim str As String
Dim i, ib, ie, icnt As Integer
Dim myDataTable As New DataTable
'Declare DataColumn ID
Dim myColumn1 As New DataColumn("ID")
myColumn1.DataType = System.Type.GetType("System.Int32")
'Add Column to table
myDataTable.Columns.Add(myColumn1)
'Declare DataColumn tYear
Dim myColumn2 As New DataColumn("tYear")
myColumn2.DataType = System.Type.GetType("System.Int32")
'Add Column to table
myDataTable.Columns.Add(myColumn2)
'Get rid of duplicates
Dim myUC As New UniqueConstraint("UC",
myDataTable.Columns("tYear"))
myDataTable.Constraints.Add(myUC)
icnt = 0
For Each dr In dsAutos.Tables("tAutos").Rows
icnt = icnt + 1
ib = Val(dr("tBYr"))
i = ib
ie = Val(dr("tEYr"))
Do Until i = ie + 1
Try
myRow = myDataTable.NewRow()
myRow("ID") = icnt
myRow("tYear") = i
Console.WriteLine(myRow("tYear"))
myDataTable.Rows.Add(myRow)
'Me.ListBoxYear.Items.Add(CStr(i))
i = i + 1
Catch
i = i + 1
End Try
Loop
Next
Console.WriteLine(icnt)
Console.WriteLine("-----")
For Each dr In myDataTable.Rows
Console.WriteLine(dr("tYear"))
Next
Dim strExp, strSort As String
'Sort
strExp = "tYear > 1900"
strSort = "tYear"
'Use the Select method to find all rows matching the filter.
Dim drsort As DataRow() = myDataTable.Select(strExp, strSort,
DataViewRowState.Added)
For Each drsort In myDataTable.Rows
Console.WriteLine(drsort("tYear"))
Next
End Function