I have a datatable with multiple columns. I want only one column from it conditionally. Help

Hi Team,

So I have a datatable as below:- (dtInput)


I need to get the Sub-Datatable from the above datatable such that the Month name shall be referred and corrospoding range is gotten in the sub-datatable.

NOTE:- I have handled the variables, just need logic or idea to extract conditional Range.
Input variables
1.:- dtInput
2.:- InputMonth

For eg:
1.:- dtInput is as shown in abve dt
2.:- InputMonth is “18-Jul”
then output sub-datatable contains below:-
image

For eg:-
1.:- dtInput is as shown in abve dt
2.:- InputMonth is “19-Mar”
then output sub-datatable contains below:-
image
Hope the examples made it clear.

Note:- I do have multiple approaches but wanted a most efficient one.

Thanks and Regards,
@hacky

Hi @hacky

Use newdt=dt.select(“Datetime.parsexact(datetime.now.tostring,“dd-mmm-yyyy”, System.globalization.cultureinfo.invariantculture)”). copy todatatable ()

@AshwinS2
Please note that I already have a variable having the InputMonth, so need to fit that variable to fit into your code.

Also the new variable “dtNew” needs to have the outputted value as shown in my question.

Please help me such that my varibles shall be used in your logic/

Also when I do that from my side it shows some error saying that end of expression was missing.

@HareeshMR
@Palaniyappan

Plz help

1 Like

Fine
one small clarification if we mention as “19-Mar” is it taking as header of the column in the datatable
Cheers @hacky

@Palaniyappan, I have created a DTinput such that “19-Mar”, “18-Apr” act as a headers

1 Like

Fine
then we can get like this directly
Finaldt = outdt.DefaultView.ToTable(False,“yourcolumnnameasstring”)

where Finaldt is a datatable variable
Cheers @hacky

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.