Solved

Filter DataSet

Posted on 2004-08-25
10
340 Views
Last Modified: 2008-02-01
Hi,

I have a dataset with multiple records.  I want to find one row in that dataset.  How do I do this?  I have two primary keys to make each row unique.  So basically I want to search the dataset based on two colum values.  Also I need to account for if nothing is returned from the serach (but there will never be two records returned).

Ryan
0
Comment
Question by:NeoTek
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 50 total points
ID: 11891685
try this

Dim vals(1) As Object
vals(0) = "searchstringfirstkey"
vals(1) = "searchstringsecondkey"
dim dr as datarow = yourdataset.Tables(0).Rows.Find(vals)

or

dim dv as new dataview = yourdataset.tables(0).defaultview
dv.sort = "yourfirstkey, yoursecondkey"
Dim vals(1) As Object
vals(0) = "searchstringfirstkey"
vals(1) = "searchstringsecondkey"
dim recordnumber = dv.find(vals)

0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11891702
dr will return nothing (if no records are found)
recordnumber will return -1 (if no records are found)
0
 
LVL 5

Assisted Solution

by:LindzK
LindzK earned 25 total points
ID: 11892382
'create an array to hold the rows fround from the search
Dim aRows() as datarow
'perform a select on the row
'SearchField = the name of the field you want to search on
'SearchTerm = the text /input that must be contained within the search field
aRows = DataSet1.Tables(0).Select("SearchField =" & SearchTerm)
if aRows.length > 0 then
  'found the row, do whatever code you need for the row
  'you found here
else
  msgbox("No rows found")
end if

It works just like performing a select statement on the database, and returns an array of rows
0
 
LVL 1

Author Comment

by:NeoTek
ID: 11892418
Hi,

I tried this...

        Dim vals(2) As Object
        vals(0) = "1001AB    " 'lstSalesman.SelectedValue
        vals(1) = 2 'Session("DivisionID")
        vals(2) = "15L       " 'lstItem.SelectedItem
        Dim dr As DataRow = DsSales.Tables("Salesman_Budget_Input").Rows.Find(vals)

        If dr Is Nothing Then
            lblTitle.Text = "Nothing"
        Else
            lblTitle.Text = "Something"
        End If

and this...

        Dim dv As DataView = DsSales.Tables("Salesman_Budget_Input").DefaultView
        dv.Sort = "DivisionID" ', DivisionID, ItemSet"
        Dim vals(2) As Object
        vals(0) = 2
        vals(1) = 2
        vals(2) = "15L"
        Dim recordnumber = dv.Find(vals)

        If recordnumber = -1 Then
            lblTitle.Text = "Nothing"
        Else
            lblTitle.Text = "Something"
        End If

Neither return anything.  I don't know what I am doing wrong.  The values do exist in the database...

Ryan
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11892469
Hi neotek,

 dv.Sort = "DivisionID" ', DivisionID, ItemSet"

 this line seems strange why twice divisionID and the syntax is wrong  (" ')

0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11892523
And also,  the first method you tried only works with primary keys (do you have 3 primary keys) ?

the second (with the dataview) works with all fields
0
 
LVL 1

Author Comment

by:NeoTek
ID: 11893179
Hi,

I'm sorry.  It was my mistake.  All three methods work.  I didn't fill my dataset initally.

NeoTek
0
 

Expert Comment

by:asadeen
ID: 14004197
I too use the dataset.select() statement to filter a dataset but I get an error, I use C#

dataSet11.NPX_CONRATES.Select(­"WHERE
ListID='"+this.ListBox1.Select­edValue+"'");


I get an error


"System.Data.SyntaxErrorExcept­ion: Syntax error: Missing operand
after 'ListID' operator."


for the above dataset filter statement.


Please help me to solve this.


Thanks
Deen


0
 
LVL 5

Expert Comment

by:LindzK
ID: 14006774
Hi Deen,

If you review the answer that I gave for useing a select on the dataset, you may notice that you have added extra words in than required.  I won't tell you exactly which one though - You see, people answer questions on this forums to earn points as well as to help people.  It is not very fair, to pose a question of your own, underneath a question that another member has already payed for and had answered.  

LindzK
0
 

Expert Comment

by:asadeen
ID: 14006942
I am sorry I am very new to this, I used to visit quite often but recently started using. However I figured out that soon after I posted my message.

Thanks
Deen
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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