Click here to Skip to main content
13,145,464 members (51,995 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
how to get column values by specific column name from datatable in c#

please help..
Posted 4-Sep-13 20:31pm
Apali358
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hi Apali, try this;

DataView dv = new DataView(Your DataTable);
 
  DataTable dt = dv.ToTable(true, "Your Specific Column Name");
 
//this dt contains only selected column values.



I hope this will help you.

Thank's
Mohan G
  Permalink  
Comments
Apali 5-Sep-13 2:51am
   
thnx a lot...i got by this code...
Apali 5-Sep-13 2:56am
   
DataView dv = new DataView(dtDataTable);
DataTable dt = dv.ToTable(true, "PONUMBER");

here i got the PONUMBER column values in dt.

how i will compare 1st index and second index value of dt...
MohanGopi 5-Sep-13 2:58am
   
you have only two rows on that dt or more rows
Apali 5-Sep-13 3:01am
   
above 100 rows are there..i have to add same values
MohanGopi 5-Sep-13 3:04am
   
you want to compare the values like;
row1=row2;
row3=row4;

are what? give some clear explanation.
Apali 5-Sep-13 3:06am
   
yes i want to compare 1st row with 2nd row
i used like this but its showing error
for (int k = 0; k < arrCostingSheetColumnList.Count; k++)
{
if (dt[k]==dt[k + 1])
{

}
}
MohanGopi 5-Sep-13 3:10am
   
try this;

int r = 0;
int r2 = 1;
foreach (DataRow dr in dt.Rows)
{
dr[r] = dr[r2];
r = r + 2;
r2 = r2 + 2;
}
this will solve your problem.
Apali 5-Sep-13 3:24am
   
hi by using below code i am getting distict column values...repeated values are not coming..but i want all the values of POVALUE column. pls help

DataView dv = new DataView(dtDataTable);
DataTable dt = dv.ToTable(true, "PONUMBER");
MohanGopi 5-Sep-13 3:35am
   
try this;
DataTable dt = dv.ToTable(false, "PONUMBER");
Apali 5-Sep-13 5:51am
   
thnx a lot..i am getting now
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Apali 5-Sep-13 2:42am
   
thnx but i want the code in c#,can you please help
Thomas ktg 5-Sep-13 2:53am
   
give me the code you tried.
Apali 5-Sep-13 2:57am
   
ya i got that one but see the below code
DataView dv = new DataView(dtDataTable);
DataTable dt = dv.ToTable(true, "PONUMBER");
here i got the PONUMBER column values in dt. how i will compare 1st index and second index value of dt...
Thomas ktg 5-Sep-13 2:56am
   
DataTable dtSelectedColumns = dtOriginal.DefaultView.ToTable(true, "Column1", "Column2");
Apali 5-Sep-13 3:33am
   
no still same problem by using this code also..i want same value in columns so i can check it is equal or not...but by this i m getting distinct column values.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web02 | 2.8.170915.1 | Last Updated 5 Sep 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100