private void SetTestDataTable()
{
DataTable dtTest = new DataTable();
dtTest.Columns.Add("Id",typeof(int));
dtTest.Columns.Add("Name",typeof(string));
dtTest.Rows.Add(1, "aaa");
dtTest.Rows.Add(2, "bbb");
dtTest.Rows.Add(3, "ccc");
dtTest.Rows.Add(4, "ddd");
dtTest.Rows.Add(5, "eee");
foreach (DataRow dr in dtTest.Rows)
{
if (Convert.ToInt16(dr["id"].ToString()) % 2 == 0)
{
dr.Delete(); //標記要刪資的資料列
}
}
dtTest.AcceptChanges(); //真正移除作業
}
沒有留言:
張貼留言