Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select certain columns of a data table

I have a datatable and would like to know if its possible for me to select certain columns and input the data on a table. the columns are set out as below

|col1 |col2 |col3|col4 |col5 |col6|col7 |col8 |col9 |col10 |col11 |

I want to select column col1, col2 col6, col7,col3. and dispay the data in a gridview of the rows within the datatable.. currently the code that i am using is below and onmly selects certain data. I am not selecting the data from sql its data being selected from another excel which is stored in a datatable.. but i am in need of the other columns in another area as well.. this data is being written into a table in word

 for (int i = 1; i < table.Rows.Count; i++)             {                 for (int j = 0; j < table.Columns.Count; j++)                 {                     if (j == 0)                     {                         val = filteredData.Rows[row][col].ToString();                     }                     else                     {                         val = filteredData.Rows[row][col].ToString();                          if (val == "-" || val == "")                         {                             val = filteredData.Rows[row][col].ToString();                          }                         else                         {                             val = Convert.ToString(Math.Round(Convert.ToDouble(filteredData.Rows[row][col]), MidpointRounding.AwayFromZero));                          }                     }                      table[j, i].TextFrame.Text = val;                     col++;                 } 
like image 615
Jim Brad Avatar asked Dec 07 '12 09:12

Jim Brad


People also ask

How do I select a specific column from a table in SQL?

To select columns, choose one of the following options: Type SELECT , followed by the names of the columns in the order that you want them to appear on the report. Use commas to separate the column names.

How do I select only certain columns in Excel?

To select non-adjacent rows or columns, hold Ctrl and select the row or column numbers.

How do I select a specific column in a Dataframe in R?

To select a column in R you can use brackets e.g., YourDataFrame['Column'] will take the column named “Column”. Furthermore, we can also use dplyr and the select() function to get columns by name or index. For instance, select(YourDataFrame, c('A', 'B') will take the columns named “A” and “B” from the dataframe.


1 Answers

Also we can try like this,

 string[] selectedColumns = new[] { "Column1","Column2"};   DataTable dt= new DataView(fromDataTable).ToTable(false, selectedColumns); 
like image 75
Ramkumar Srinivasan Avatar answered Sep 20 '22 11:09

Ramkumar Srinivasan