---
title: "How to get records of specific columns of data table using c#."  
description: "How to get records of specific columns of data table using c#."  
author: "James Smith"  
published: 2011-07-23  
updated: 2019-04-05  
canonical: https://www.mindstick.com/forum/274/how-to-get-records-of-specific-columns-of-data-table-using-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# How to get records of specific columns of data table using c#.

Hi,

I have a small [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) while making a [program in c#](https://www.mindstick.com/forum/34674/how-can-write-a-console-program-in-c-sharp). The problem is that I would like to [access](https://www.mindstick.com/articles/12994/how-foreigners-can-access-blocked-websites-in-china) record of selected columns of data [table in c#](https://www.mindstick.com/forum/159584/what-are-the-differences-between-a-hashmap-and-a-hash-table-in-c-sharp). Like suppose I have a data table which have four columns namely empId, empName, empAge and empCity . Now I would like to [select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) record of only two columns of this data table. This is prity [simple](https://yourviews.mindstick.com/story/1469/5-simple-ways-to-stay-fit-amp-healthy) in [sql query](https://www.mindstick.com/forum/529/rename-table-name-and-column-name-using-sql-query) but how can I perform it into data table.

Help me!

Thanks.

## Replies

### Reply by Anonymous User

Hi James,

You can easily select records of selected columns in DataTable. Check the code below.

DataTable dtSelectedColumns = dtOriginal.DefaultView.ToTable(false, "Column1", "Column2");

If you want those columns with distinct records then pass first parameter true except false. You can also provide as many column as you want in the parameter.

### Reply by Anonymous User

Hi james,

You can get information of selected columns in following way,

```
string[] selectedColumns = new[] { "ID", "LastName" };  //It represent name of column for which you want to select recordsDataTable tableWithOnlySelectedColumns = new DataView(table).ToTable(false, selectedColumns);
```

//Here [table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap) represent name of that DataTable which have all columns.

Thanks.

Please mark it as answer if your problem had been resolved.

``


---

Original Source: https://www.mindstick.com/forum/274/how-to-get-records-of-specific-columns-of-data-table-using-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
