Avatar of chokka
chokka
Flag for United States of America asked on

How to filter Dataset in Vb.Net

My actual dataset - tempDS populates more than one datatable.

I need to filter the dataset for the DataTable : tree_categories

Sample query

select * from tree_categories where GROUP_CODE <> PA.43.948'

DataTable : tree_Categories

Column Name : GROUP_CODE


Dim tempDs As DataSet = ds
Dim dtTable As DataTable = tempDs.Tables("p_tree_categories")


How to filter a Dataset in Vb.Net ?
C#.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
chokka

8/22/2022 - Mon
SOLUTION
Ali HND

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
chokka

ASKER
@a_hnd , thank you !! I am returning the dataset in my function.

I am expecting the tempDS to be populated with filtered row of records and return in the function.

Is it possible to achieve in this syntax ??
chokka

ASKER
actual method


Public Function LoadBaseTree(ByVal ds As DataSet) As Boolean

Dim result As Boolean = False

Dim tempDs As DataSet = ds

 

If BaseTreeLoaded = False Then

If ShowProductNotInElement = True Then
'implement function to append product not in element

tempDs = mergeTables(ds)


End If

result = MyBase.ApplySelectionCriteriaData(tempDs, Me.Name, GroupTableName, ItemTableName, GroupItemTableName, MyBase.ValidatorItemTableName, MyBase.ValidatorItemDataTableName, True, True, True, True)

If result = True Then
_baseTreeLoaded = True

End If

Else
ClearSelections()

result = True

End If
Return result
End Function

Open in new window

ASKER CERTIFIED SOLUTION
Miguel Oz

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Ali HND

'Your Codes
'.
'.
'.
Dim result() As DataRow = dtTable.Select("GROUP_CODE <> 'PA.43.948'")
Dim FunctionResualt As Boolean = False
If result IsNot Nothing Then
    FunctionResualt = True
Else
    FunctionResualt = False
End If
Return FunctionResualt
End Function

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
chokka

ASKER
When i write the merge syntax

tempDs.Merge(ds.Tables("p_tree_categories").Select( "GROUP_CODE <> 'PA.43.948'"))


My original ds has 23 tables.

On writing merge, i am able to get only p_tree_categories table. I am not  able to include remaining 22 tables.

In my req, i need to get all the tables in the Dataset. Along with filtered - p_tree_categories
chokka

ASKER
tempDs.Merge(ds.Tables("p_tree_categories").Select( "GROUP_CODE <> 'PA.43.948'"))

tempDs.Merge(ds,True)

After writing the syntax,i am able to get the remaining 22 tables. Values populating the duplicate value of records.
chokka

ASKER
I am merging all my ds.Tables to my test Dataset.

Issue is : testDs.Merge(ds.Tables("p_tree_data"))  - p_tree_data doesnt have row of records. When there is no row of records, table has to be merged with Dataset. Right now, when there is no row of records, table is not get merged. How to fix this issue
 

  Dim testDs As DataSet = New DataSet()

        testDs.Merge(ds.Tables("p_pay_cmp_cursor"))
        testDs.Merge(ds.Tables("p_pay_cmp_pln_cursor"))
        testDs.Merge(ds.Tables("p_currency_cursor"))
        testDs.Merge(ds.Tables("p_tree_categories").Select("SCR_DPY_SEQ <> '20116000'"))
        testDs.Merge(ds.Tables("p_tree_data"))
        testDs.Merge(ds.Tables("p_prod_override_cursor"))
        testDs.Merge(ds.Tables("p_tree_val_item"))
        testDs.Merge(ds.Tables("p_tree_val_item_data"))
        testDs.Merge(ds.Tables("p_bonus_cat_cursor"))
        testDs.Merge(ds.Tables("p_bonus_item_cursor"))
        testDs.Merge(ds.Tables("p_managed_results"))
        testDs.Merge(ds.Tables("p_tree_group_categories"))
        testDs.Merge(ds.Tables("p_component_type_cursor"))
        testDs.Merge(ds.Tables("p_ref_data_cursor"))
        testDs.Merge(ds.Tables("p_meas_typ_cursor"))
        testDs.Merge(ds.Tables("p_measurement_period_cursor"))
        testDs.Merge(ds.Tables("p_cap_typ_cursor"))
        testDs.Merge(ds.Tables("p_pay_calc_mth_cursor"))
        testDs.Merge(ds.Tables("p_calc_typ_cursor"))
        testDs.Merge(ds.Tables("p_pay_freq_cursor"))
        testDs.Merge(ds.Tables("p_payout_typ_cursor"))
        testDs.Merge(ds.Tables("p_perf_source_cursor"))
        testDs.Merge(ds.Tables("p_custom_type_cursor"))

Open in new window

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
chokka

ASKER
I am using merge syntax. Thank you Miguel.