Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select column from datatable and convert this to datatable again

Tags:

c#

datatable

I want to select one column in an DataTable in C#, this column should be transform also in an DataTable.

This is what I want.

DataTable(many columns) > select one column > convert this column to a DataTable again

I have try this, but this give me the complete DataTable back.

DataTable dt = defindedDataTable.Columns[0].Table;
like image 674
Higune Avatar asked Jul 05 '26 15:07

Higune


1 Answers

You can get the DataView from your table and then use the DataView.ToTable Method. With this method, you can select one or more column you want:

DataTable dt = defindedDataTable.DefaultView.ToTable(false, defindedDataTable.Columns[0].ColumnName);
like image 168
Chris Avatar answered Jul 07 '26 04:07

Chris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!