I have a data table which has few rows and columns. I need to delete the entire data along with column names also.
Eg :
Item | 2017 | 2018 | 2019 | 2020
----------------------------------
A 400 200 300 500
B 400 300 500 100
C 100 200 500 300
D 100 300 400 100
I need to delete all the data of the above data table along with the column names so that I can re-use the same data table for storing other values.
I tried datatable.clear() method it is clearing only the data, the column names remain intact and also I can't use dispose().
How can I do it.?
This should work:
datatable.Clear() 'clear records
datatable.Constraints.Clear() 'clear constraints (required before Columns.Clear(), if there is any constraint)
datatable.Columns.Clear() 'clear columns
Or this:
datatable.Reset()
But if you want to just create a new "blank" instance, or in other words, reinitialize it:
datatable = New Datatable
Short version here:
Dim dt As New DataTable
'...
'you do some operations
'...
dt = New DataTable 'renew the same instance
Alternatively, you can use:
dt = Nothing 'basically setting it to NULL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With