Home > DeveloperSection > Forums > How to Get a Specific Column Value from a DataTable?
Tarun Kumar

Total Post:210

Points:1614
Posted on    February-24-2016 5:12 AM

 C# C#  ADO.Net  .NET  Winforms 
Ratings:


 1 Reply(s)
 406  View(s)
Rate this:

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



Uttam Misra

Total Post:124

Points:888
Supported
Posted on    February-24-2016 5:21 AM

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();


Don't want to miss updates? Please click the below button!

Follow MindStick