Datatable without using column refference

datatable
uiautomation
activities
studio

#1

Hi All,

can we filter the datatable without using column refference.

Thanks,
Vikram Mahit


#2

Hi @vikrammahit,

i think you can’t filter without column name but you can filter using Column index if you don’t know the column name.

Refer below code

dt.DefaultView.Sort = sortColumn
dt = dt.DefaultView.ToTable()
instead of

sortColumn = "3 desc, 4 desc"

you can use

sortColumn = dt.Columns[3].ColumnName + " DESC," + dt.Columns[4].ColumnName + " DESC"

dt.DefaultView.Sort = sortColumn
dt = dt.DefaultView.ToTable()

Regards,
Arivu


#3

Hello,

Column Name and Column index are not fixed for my table, we are searching for value which can available anywhere in the datatable


#4

Hi @vikrammahit,

Try this one, here stringValue checking anywhere in the datatable, if anything match it will return the value.

DataTable dt=(From row in dt.Select() Where String.Join("", row.ItemArray()).Contains(stringValue) Select row).ToArray().CopyToDataTable()

Regards,
Arivu


#5

Hello @arivu96 ,

Thanx for the solution, it is working fine.
is there have any options to get the index of that value from datatable


#6

Try this one

rowIndex =(dt.Rows.IndexOf(dt.AsEnumerable().Where(Function(row) String.Join("", row.ItemArray()).ToString.Contains(“word”)).ToArray()(0))+1).ToString

Regards,
Arivu


#7

Thanx arivu, Working exactly as per the conditions