How to Get a Specific Column Value from a DataTable?

I want to fetch a certain column value based on the user input lets say the datatable has two columns ID and CountryName.

I need to find ID in the datatable based on the user input country name. 

please help

Last updated:2/24/2016 5:21:34 AM

1 Answers

Uttam Misra
Uttam Misra

Here you go:

string Name = 'MARK';
DataTable dt = new DataTable();
int ID= (from DataRow dr in dt.Rows
              where (string)dr['Name'] == Name
              select (int)dr['ID']).FirstOrDefault();