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


#1

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


#2

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


#3

@MahalingPatil i dont want go with loop


#4

@Manjuts90

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

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

What if it contains Duplicate Names in Name Column

Regards,
Mahesh


#5

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


#6

You can use select function to do the same.

Datatable.DataTable_Select.xaml (7.4 KB)


#7

dt.select(“a=’”+yourvalue"’)(0)(1)


#8

@Manjuts90

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”)

Regards,
Mahesh