[C#] DataTable 빈 행 제거하기

Jeini·2023년 7월 25일
0

🍇 C#

목록 보기
3/5
post-thumbnail

public void RemoveEmptyRows(DataTable dataTable)
    {
        for (int i = dataTable.Rows.Count - 1; i >= 0; i--)
        {
            DataRow row = dataTable.Rows[i];
            bool isRowEmpty = true;

            foreach (var item in row.ItemArray)
            {
                if (!string.IsNullOrWhiteSpace(item.ToString()))
                {
                    isRowEmpty = false;
                    break;
                }
            }

            if (isRowEmpty)
            {
                dataTable.Rows.RemoveAt(i);
            }
        }
    }
profile
Fill in my own colorful colors🎨

0개의 댓글