Link to home
Start Free TrialLog in
Avatar of chokka
chokkaFlag 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 ?
SOLUTION
Avatar of Ali HND
Ali HND
Flag of Iran, Islamic Republic of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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 ??
Avatar of 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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
'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

Avatar of 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
Avatar of 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.
Avatar of 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

Avatar of chokka

ASKER

I am using merge syntax. Thank you Miguel.