2010-07-22 63 views
0

我最近在一個測試中被問到這個問題,我沒有通過。對我而言,我無法發現問題所在。這可能也是很明顯的,但即使是我的同事也無法發現。我能想到的最好的是瓶頸和命名參數不一致的問題!我責怪事實上,我也沒有做過任何vb.net多年來,我一直在做C#主要是這些天:)DataTable排序測試問題

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 

的問題是:這個功能,雖然會成功排序的數據表,它有一個主要問題。問題是什麼?使用LINQ在C#或VB.Net中重寫函數。

回答

0

DataTable被克隆,然後與它自己的克隆合併?很奇怪..

0

在C#中,我使用

使用類型化的DataSet 創建precising類型的數據的DataTable

for example i have create a dsAppointment 

    DsAppointment dsAppointmentTmp = new DsAppointment(); 
    DsAppointment dsAppointment = new DsAppointment(); 
    //add all appointment 
    dsAppointmentTmp.Appointment.AddAppointmentRow(name,start,end,body) 
    //use select(filter,sort(name of columns) 
    DataRow[] rows1 = dsAppointmentTmp.Tables[0].Select(string.Empty, dsAppointmentTmp.Tables[0].Columns[1].ToString()); 

       foreach (DataRow thisRow in rows1) 
       { 
         dsAppointment.Tables[0].Rows.Add(thisRow.ItemArray); 

       } 
//return dsAppointment sorted 
       return dsAppointment;