How remove columns from ADO.NET DataTable?

  • Thread starter Thread starter Ronald S. Cook
  • Start date Start date
R

Ronald S. Cook

I have an ADO.NET DataTable with several columns. I would like to remove
some columns. How can I do this. please?
 
Actually, removing the columns is easy. It's that the when I assign one
datatable to another and then remove columns, it seems ot afect BOTH
datatables.

tblHistoryForChart = tblHistoryForGrid

tblHistoryForChart.Columns.Remove("Col1")

tblHistoryForChart.Columns.Remove("Col4")

tblHistoryForChart.Columns.Remove("Col6")

Thanks.
 
Nevermind. tbl.Copy() was the way to go.

Ronald S. Cook said:
Actually, removing the columns is easy. It's that the when I assign one
datatable to another and then remove columns, it seems ot afect BOTH
datatables.

tblHistoryForChart = tblHistoryForGrid

tblHistoryForChart.Columns.Remove("Col1")

tblHistoryForChart.Columns.Remove("Col4")

tblHistoryForChart.Columns.Remove("Col6")

Thanks.
 
Don't forget that you're working with object references.
Your line tblHistoryForChart = tblHistoryForGrid means that both the
variables are pointing to the same memory location, so updating any
properties/ calling any methods on either will indeed affect both
variables
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top