Solved

How to filter Dataset in Vb.Net

Posted on 2014-12-26
9
703 Views
Last Modified: 2014-12-28
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 ?
0
Comment
Question by:chokka
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
9 Comments
 
LVL 3

Assisted Solution

by:Ali HND
Ali HND earned 250 total points
ID: 40519347
Hi
Dim tempDs As DataSet = ds
Dim dtTable As DataTable = tempDs.Tables("p_tree_categories")
Dim result() As DataRow = dtTable.Select("GROUP_CODE <> 'PA.43.948'")
For Each row As DataRow In result
	    Console.WriteLine(row(0))
Next

Open in new window

0
 

Author Comment

by:chokka
ID: 40519348
@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 ??
0
 

Author Comment

by:chokka
ID: 40519358
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

0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 36

Accepted Solution

by:
Miguel Oz earned 250 total points
ID: 40519361
The below code fills the temp dataset with the filtered info:
'create new dataset
Dim tempDs As DataSet = New DataSet()
'Use the merge method to add filtered table
tempDs.Merge(ds.Tables("p_tree_categories").Select( "GROUP_CODE <> 'PA.43.948'"))

Open in new window

0
 
LVL 3

Expert Comment

by:Ali HND
ID: 40519371
'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

0
 

Author Comment

by:chokka
ID: 40519747
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
0
 

Author Comment

by:chokka
ID: 40519772
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.
0
 

Author Comment

by:chokka
ID: 40520085
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

0
 

Author Closing Comment

by:chokka
ID: 40520815
I am using merge syntax. Thank you Miguel.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question