把datatable的某些数据提取出来放在另一个表中
/// <summary>
/// 把table表里的某行数据提取出来放到别一个表中,并在原表中删除这行数据
/// </summary>
/// <param name="startDatatable">源表</param>
/// <param name="indexKey">提取行号</param>
/// <returns>返加datatable数组。第一个数组是源表,第二个数组是目标组</returns>
public static DataTable[] CheckDatatable(DataTable startDatatable, int indexKey)
{
DataTable dbdbTongmadeplayfulelementHead = startDatatable.Clone();
int intRowCount = startDatatable.Rows.Count;
if ((intRowCount > 0) && (intRowCount > indexKey))
{
DataRow dr = dbdbTongmadeplayfulelementHead.NewRow();
dr.ItemArray = startDatatable.Rows[indexKey].ItemArray;
dbdbTongmadeplayfulelementHead.Rows.Add(dr);
DataRow tempdatarow = startDatatable.Rows[indexKey];
startDatatable.Rows.Remove(tempdatarow);
startDatatable.AcceptChanges();
return new DataTable[] { startDatatable, dbdbTongmadeplayfulelementHead };
}
else
{
return null;
}
}
/// <summary>
/// 把table表里的某行数据提取出来放到别一个表中,并在原表中删除这些数据
/// </summary>
/// <param name="startDatatable">源表</param>
/// <param name="StartindexKey">起适行号</param>
/// <param name="EndindexKey">结束行号</param>
/// <returns>返加datatable数组。第一个数组是源表,第二个数组是目标组</returns>
public static DataTable[] CheckDatatable(DataTable startDatatable, int StartindexKey, int EndindexKey)
{
DataTable dbdbTongmadeplayfulelementHead = startDatatable.Clone();
int intRowCount = startDatatable.Rows.Count;
if ((intRowCount > 0) && (intRowCount >= StartindexKey) && (intRowCount >= EndindexKey))
{
for (int i = StartindexKey; i <= EndindexKey; i++)
{
DataRow dr = dbdbTongmadeplayfulelementHead.NewRow();
dr.ItemArray = startDatatable.Rows[i].ItemArray;
dbdbTongmadeplayfulelementHead.Rows.Add(dr);
}
int j = 0;
do
{
DataRow tempdatarow = startDatatable.Rows[StartindexKey - j];
startDatatable.Rows.Remove(tempdatarow);
j++;
StartindexKey++;
} while (StartindexKey <= EndindexKey);
startDatatable.AcceptChanges();
return new DataTable[] { startDatatable, dbdbTongmadeplayfulelementHead };
}
else
{
return null;
}
}
/// 把table表里的某行数据提取出来放到别一个表中,并在原表中删除这行数据
/// </summary>
/// <param name="startDatatable">源表</param>
/// <param name="indexKey">提取行号</param>
/// <returns>返加datatable数组。第一个数组是源表,第二个数组是目标组</returns>
public static DataTable[] CheckDatatable(DataTable startDatatable, int indexKey)
{
DataTable dbdbTongmadeplayfulelementHead = startDatatable.Clone();
int intRowCount = startDatatable.Rows.Count;
if ((intRowCount > 0) && (intRowCount > indexKey))
{
DataRow dr = dbdbTongmadeplayfulelementHead.NewRow();
dr.ItemArray = startDatatable.Rows[indexKey].ItemArray;
dbdbTongmadeplayfulelementHead.Rows.Add(dr);
DataRow tempdatarow = startDatatable.Rows[indexKey];
startDatatable.Rows.Remove(tempdatarow);
startDatatable.AcceptChanges();
return new DataTable[] { startDatatable, dbdbTongmadeplayfulelementHead };
}
else
{
return null;
}
}
/// <summary>
/// 把table表里的某行数据提取出来放到别一个表中,并在原表中删除这些数据
/// </summary>
/// <param name="startDatatable">源表</param>
/// <param name="StartindexKey">起适行号</param>
/// <param name="EndindexKey">结束行号</param>
/// <returns>返加datatable数组。第一个数组是源表,第二个数组是目标组</returns>
public static DataTable[] CheckDatatable(DataTable startDatatable, int StartindexKey, int EndindexKey)
{
DataTable dbdbTongmadeplayfulelementHead = startDatatable.Clone();
int intRowCount = startDatatable.Rows.Count;
if ((intRowCount > 0) && (intRowCount >= StartindexKey) && (intRowCount >= EndindexKey))
{
for (int i = StartindexKey; i <= EndindexKey; i++)
{
DataRow dr = dbdbTongmadeplayfulelementHead.NewRow();
dr.ItemArray = startDatatable.Rows[i].ItemArray;
dbdbTongmadeplayfulelementHead.Rows.Add(dr);
}
int j = 0;
do
{
DataRow tempdatarow = startDatatable.Rows[StartindexKey - j];
startDatatable.Rows.Remove(tempdatarow);
j++;
StartindexKey++;
} while (StartindexKey <= EndindexKey);
startDatatable.AcceptChanges();
return new DataTable[] { startDatatable, dbdbTongmadeplayfulelementHead };
}
else
{
return null;
}
}
本人博客的文章大部分来自网络转载,因为时间的关系,没有写明转载出处和作者。所以在些郑重的说明:文章只限交流,版权归作者。谢谢