이 마십시오 :
static DataTable GetTable()
{
// Here we create a DataTable with four columns.
DataTable table = new DataTable();
table.Columns.Add("Item1", typeof(string));
table.Columns.Add("Item2", typeof(string));
table.Columns.Add("Item3", typeof(string));
table.Columns.Add("Item4", typeof(string));
// Here we add five DataRows.
table.Rows.Add("a", "as", "asd", "");
table.Rows.Add("b", "asd", "asd", "");
table.Rows.Add("c", "a", "asd", "");
table.Rows.Add("d", "a", "asd", "");
table.Rows.Add("", "", "", "a");
table.Rows.Add("", "", "", "d");
table.Rows.Add("", "", "", "asd");
return table;
}
DataTable dt = GetTable();
foreach (DataRow dr in dt.Rows)
{
if (!String.IsNullOrEmpty(dr["Item4"].ToString()) && String.IsNullOrEmpty(dr["Item1"].ToString()))
{
dr["Item1"] = dr["Item4"].ToString(); //assign value of column 4 to column1
}
}
dt.Columns.Remove("Item4"); //delete column 4
더 정교한 것
다음는 예상 출력? –
@ user6002727 첫 번째 행의 내용이 동일하면 열을 병합하고 싶습니다. –
하지만 첫 번째 열에 ** asd **가 없습니까? 그래서 당신은 어떻게 예상 결과를 줄 수 있습니까? –