HOW TO GET A SPECIFIC COLUMN VALUE FROM A DATATABLE?

Tarun Kumar

Total Post:214

Points:1642
Posted by  Tarun Kumar
C#
 720  View(s)
Ratings:
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

  1. Uttam Misra

    Post:126

    Points:906
    Re: How to Get a Specific Column Value from a DataTable?

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!