Click here to Skip to main content
15,886,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to get column values by specific column name from datatable in c#

please help..
Posted

Hi Apali, try this;

C#
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
 
Share this answer
 
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...
Mohan Gopi 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
Mohan Gopi 5-Sep-13 3:04am    
you want to compare the values like;
row1=row2;
row3=row4;

are what? give some clear explanation.
 
Share this answer
 
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900