Is there a difference between DataTable.Clear and DataTable.Rows.Clear?

后端 未结 7 1571
天涯浪人
天涯浪人 2021-01-18 06:51

I recall there is a difference between some methods/properties called directly on the DataTable class, and the identically named methods/properties on the DataTable.Rows pro

7条回答
  •  攒了一身酷
    2021-01-18 07:44

    AFAIK, the main difference between datatable.clear and datatable.rows.clear, is that datatable.clear clears both rows and columns. So if you want to keep the table structure (i.e. columns), use datatable.rows.clear. And if you want to start from scratch, use datatable.clear, or even datatable.reset to go right back to the beginning.

    datatable.reset is effectively the next level up from datatable.clear. Using datatable.clear will fail if there are any constraints applied that would be violated, but using datatable.reset will get rid of anything and everything that has been put in place since the datatable was created.

提交回复
热议问题