我最近在一次考试中被问到了这个问题,但我没有通过。不管怎么说,我都找不出问题出在哪里。这可能也是很明显的事情,但就连我的一个同事也看不出来。我能想到的最好的就是瓶颈和参数命名不一致的问题!我将其归咎于我多年来没有做过任何vb.net,这些天我主要在做C# :)
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中重写函数。
发布于 2010-07-23 00:07:01
DataTable被克隆,然后与它自己的克隆合并?很奇怪..
发布于 2012-02-28 03:43:15
在c#中,我使用
使用类型化数据集在精确类型的数据中创建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;https://stackoverflow.com/questions/3310726
复制相似问题