views:

33

answers:

1

I was asked this question recently in a test, which I didn't pass. For the life of me, I couldn't spot what the problem was. It's probably something really obvious as well, but even a colleague of mine couldn't spot it either. The best I could come up with was issues with bottlenecks and naming inconsistencies of parameters! I blame it on the fact I've not done any vb.net for years, I've been doing C# mostly these days :)

Private Function sorttable(ByVal dt As DataTable, ByVal sorttype$, ByVal sort_direction$) As DataTable
    Dim dv As DataView
    Dim dt2 As DataTable
    dt2 = dt.Clone
    dt2.Merge(dt)
    dv = dt2.DefaultView
    dv.Sort = sorttype & " " & sort_direction
    Return dv.ToTable()
End Function

The question: This function, although it will successfully sort a datatable, has a major problem with it. What is the problem? Re-write the function in either C# or VB.Net using LINQ.

A: 

The DataTable is cloned and then merged with it own clone? Very strange..

codymanix
Andrew Johns