Datatable without using column refference

Hi All,

can we filter the datatable without using column refference.

Thanks,
Vikram Mahit

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

Hello,

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

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

Hello @arivu96 ,

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

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

Thanx arivu, Working exactly as per the conditions