I have a datatable into which i insert data then display the data in a
datagridview.When i want to clear the table and place completely new
data in the table, the table still retains the column headers(this is
using the datatable.Clear() method).The table then adds the new
headers to the old which results in empty columns.Please inform me how
to clear the data completely.thanks
QC - 11 Jan 2008 08:08 GMT
Datatable.Clear() methods clears only the data.
if you want to remove / clear all columns as well from it, use
DataTable.Columns.Clear() method.
Marc Gravell - 11 Jan 2008 08:13 GMT
> the table still retains the column headers
That is exactly as per the documentation (which only claims to remove
the rows):
http://msdn2.microsoft.com/en-us/library/system.data.datatable.clear.aspx
If you want to also clear the columns, then perhaps call
.Columns.Clear() - but to be honest, if you're doing that I'd be
tempted to simply throw the entire DataTable away and start with a new
one...
Marc
cameljs18@yahoo.com - 11 Jan 2008 09:37 GMT
On Jan 11, 9:59 am, camelj...@yahoo.com wrote:
> I have a datatable into which i insert data then display the data in a
> datagridview.When i want to clear the table and place completely new
> data in the table, the table still retains the column headers(this is
> using the datatable.Clear() method).The table then adds the new
> headers to the old which results in empty columns.Please inform me how
> to clear the data completely.thanks
thanks works fine now