How to find unique value from a column

HI ,

i am using a datatable to find unique values from a column.

uniqueinvoice = InvoiceData.DefaultView.ToTable(true, InvoiceData.Columns.Item(0).ToString)

here uniqueinvoice is a datatable and invoiceData is another datatable in which i have duplicate values so i used the above code to find the unique values. But when i tried to run the code i get the below error. Kindly help


Hi @Asha_chandran
To get the distinct value from column Use the following code
Yourdatatablevariable.DefaultView.ToTable(true,“YourcolumName”) .


you were almost right buddy
but the thing is we need to mention the column name in defaultview rather to the value in the column as InvoiceData.Columns.Item(0).ToString is a value in first column and not a columnname
so we need to mention like this buddy

uniqueinvoice = InvoiceData.DefaultView.ToTable(True, InvoiceData.Columns(0).Columnname.ToString)
or if we know the column name then we can directly mention the column name like this
uniqueinvoice = InvoiceData.DefaultView.ToTable(True, “yourcolumnname”)

For more details on this method

Fine apart from this the reason behind the error is
the value of InvoiceData.Columns(0).Columnname.ToString is null, thats why it was throwing error…kindly check once with the column value in that column whether it has any value or not…

thats all buddy you are done…hope this would help you
Kindly try this and let know for any queries or clarification
Cheers @Asha_chandran

Hi @Asha_chandran,
Can you please show me your workflow because i dont see any wrong in your code and once again check the data type of uniqueinvoice.
And also the return type of InvoiceData.DefaultView.ToTable(true, InvoiceData.Columns.Item(0).ToString).

Can anyone please give me a simple sample code to sort out the issue?

i am still facing with the same issue

Main.xaml (8.7 KB) invokecall.xaml (7.9 KB)

Can anyone help me to sort out the issue in the attached file?

Hi @Asha_chandran,

The Error you’re getting, NullReferenceException it happens when you try to access a reference variable that isn’t referencing any object. So that it’ll be treated as null Reference

here’s the xaml file, check the Build Datatable data and run it, and you’ll get the idea.
invokecall.xaml (7.0 KB)

image —> image

how to find unique value from a two columns?