Select specific Value from DataTable using LINQ

I am having a datatable having Id, System and Date.

I want to extract specific date (a single String/List) based on ID and system.

Please help how to get this using LINQ.

MYDT.AsEnumerable().Where(Function(x) x(“Id”).ToString = row(“ID”).ToString And x(“Name”).ToString = row(“Name”).ToString ).Select(Function(y) y MappedDate).List

Hi,
You can use a select query like this
datatable.select(“columnName= 'value '”) this will give you array of datarow.

Let us know if this helps,
Regards,
Pavan H

1 Like

Try below query.

(from rw in MYDT where rw(“ID”) = x(“ID”) and rw(“Name”) = x(“Name”) select rw(“Date”)).ToList

1 Like

thanks @deepesh.solanki and @pavanh003 . It was helpful. Also I am doing this
and saving this to a datatable however if there is no record, it thorws exception.

Can u suggest here how to handle null value.

Dt_CheckFIle2.Select(“Convert([Cost Centre],‘System.String’)='”+CostCode.ToString()+“'”).CopyToDataTable()

@p4uk80 You can run this query in try block and in catch block check the exception message if exception.message = “The source contains no DataRows” than assign some value like True/False in variable and if message is deferent then rethrow the exception.

you can try in this way.

Hey,
Once you can check for the count and if condition to check if count greater than zero.

Let us know if this helps,
Regards,
Pavan H