How to Get a Specific Column Value from a DataTable?

Total Post:214

Points:1642

C#
 1288  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. 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();

      Modified On Apr-11-2018 01:54:04 AM

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.