Solved

How to filter Dataset in Vb.Net

Posted on 2014-12-26
9
495 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
  • 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
 
LVL 35

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now