昨天,今天,明天,每天的每天,你是否都多懂得一点点...

星期二, 七月 08, 2008

c# remove end empty lines of data table.

     RemoveEndEmptyLines(ref dt2, dt2.Rows.Count - 1);


        public bool IsEmptyLine(DataTable dt, int index)
        {

            bool isEmpty = true;
            int iColCount = dt.Columns.Count;
            for (int i = 0; i < iColCount; i++)
            {
               // Console.WriteLine(dt.Rows[index][i]);
                if (!Convert.IsDBNull(dt.Rows[index][i]))
                {
                    isEmpty = false;
                    break;
                }

            }
            return isEmpty;
        

        }
        private void RemoveEndEmptyLines(ref DataTable dt, int index)
        {
            if (IsEmptyLine(dt, index))
            {
                MessageBox.Show("empty");
                dt.Rows.RemoveAt(index);
                RemoveEndEmptyLines(ref dt, index - 1);

            }
        }

没有评论:

其它博客地址

此博客的同步博客地址: http://fengnz.wordpress.com
这里进入我的MSN SPACE.