How can i get value in second column based on value in first column in a datatable

my datatable has 2 columns name and country. If i give input value present in name cloumn i have to get corresponding value in country column.

example: datatable: name country
a india
b Aus

input : a
Output : india

Please no loop concept

If (row.item(0).tostring=uservalue)
print row.item(1).tostring

@MahalingPatil i dont want go with loop


Extract both Name Column to List A
Extract Column Country to List B

Country Name=ListB(ListA.IndexOf(“Name”))

What if it contains Duplicate Names in Name Column


@MAHESH1 its a lengthy process bro looping is better than this concept.

You can use select function to do the same.

Datatable.DataTable_Select.xaml (7.4 KB)

1 Like“a=’”+yourvalue"’)(0)(1)

1 Like


Suppose if you have the people with same name but different country then you can do like this.

Create a dictionary with Key as String, and Value as String Array.

Dictionary = (From p In dta.Select
Group p By Gender=p("Name").ToString Into GroupA = Group
Select GroupA).ToDictionary(Function(x) x(0)("Name").ToString,Function(y) y.Select(Function(z) z("Country Name").ToString).ToArray)

Now you can get all the counries of the people having same Name.

Suppose if the countries are Unique then you can try like this

Country Name =Dictionary(“Name”)(0).ToString

If You want all the Countries of the people having same name
Country Name[] = Dictionary(“Name”)


1 Like