anm*_*rti 11 c# linq asp.net datatable dataset
我想在asp.net DataTable上获取一个特定的行,并将其移动到第一个基于列column1值的DataTable基础上.我的数据表dt1是通过数据库查询填充的,要搜索的值是来自另一个数据库的另一个查询,因此我不知道当时要搜索的值dt1 select.
// I use this variable to search into
// DataTable
string valueToSearch = "some value";
所以我需要some value在列中搜索我的DataTable中的值column1.然后将整行移动到第一个位置.
谢谢.
anm*_*rti 28
我们必须在之前克隆行数据:
            DataRow[] dr = dtable.Select("column1 ='" + valueToSearch +"'");
            DataRow newRow = dtable.NewRow();
            // We "clone" the row
            newRow.ItemArray = dr[0].ItemArray;
            // We remove the old and insert the new
            ds.Tables[0].Rows.Remove(dr[0]);
            ds.Tables[0].Rows.InsertAt(newRow, 0);