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

Total Post:214

Posted on    February-24-2016 5:12 AM

 C# C#  ADO.Net  .NET  Winforms 

 1 Reply(s)
 660  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:125

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