Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 at 5-Sep-13 2:51am
   
thnx a lot...i got by this code...
Apali at 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 at 5-Sep-13 2:58am
   
you have only two rows on that dt or more rows
Apali at 5-Sep-13 3:01am
   
above 100 rows are there..i have to add same values
MohanGopi at 5-Sep-13 3:04am
   
you want to compare the values like;
row1=row2;
row3=row4;
 
are what? give some clear explanation.
Apali at 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 at 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 at 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 at 5-Sep-13 3:35am
   
try this;
DataTable dt = dv.ToTable(false, "PONUMBER");
Apali at 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 at 5-Sep-13 2:42am
   
thnx but i want the code in c#,can you please help
Thomas ktg at 5-Sep-13 2:53am
   
give me the code you tried.
Apali at 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 at 5-Sep-13 2:56am
   
DataTable dtSelectedColumns = dtOriginal.DefaultView.ToTable(true, "Column1", "Column2");
Apali at 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
0 Gihan Liyanage 332
1 Sergey Alexandrovich Kryukov 230
2 ClimerChinna 222
3 vikinghunter 178
4 OriginalGriff 161
0 Sergey Alexandrovich Kryukov 8,373
1 OriginalGriff 7,112
2 CPallini 2,598
3 Richard MacCutchan 2,025
4 Abhinav S 1,788


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 5 Sep 2013
Copyright © CodeProject, 1999-2014
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