Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Filter DataSet

Posted on 2004-08-25
10
Medium Priority
?
347 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
[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
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 200 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 100 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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 …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

610 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