实名认证用户熊川湘 身份证号码430811198506290914

把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;
            }
        }
posted @ 2010-04-21 17:53  浪达短信群发  阅读(310)  评论(0编辑  收藏  举报