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

x
?
Solved

How can I use a dataviews .Find method to get the index of a row with composite key?

Posted on 2004-04-19
2
Medium Priority
?
385 Views
Last Modified: 2010-04-24
Hi,
I have been trying this code to get the index:

        Dim dv As DataView
        Dim pk(1) As Object
        dv = New DataView(ds.Tables("custOrderItem"))
        dv.Sort = "orderid, menuItemId"
        'Find the custOrderItem matching orderId and menuItemId
        With dr 'a reference to the row I am working with
            pk(0) = .Item("orderid")
            pk(1) = .Item("menuItemId")
        End With
        Try
            i = dv.Find(pk)
        Catch ex As Exception
            MsgBox(ex.Message & vbCrLf & ex.GetType.ToString)
        End Try

orderId & menuItemId have values such as 1,2,3,4,5......

I need the index of the specific row so I can change the bindingContext .Position to match this row.

This code works sometimes, but then other times it gives me the wrong index. Always when I'm looking for certain row(s) index it gives me the wrong index.

Is there any way to make this more reliable??

Thanks.
0
Comment
Question by:Tiare
[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
2 Comments
 
LVL 7

Accepted Solution

by:
ramesh12 earned 1000 total points
ID: 10864991
You can use RowFilter to find the row meeting your criteria like

dv.rowfilter "orderid=yourvalue and menuitemid=yourvalue1)

Now you can use your dataview
0
 

Author Comment

by:Tiare
ID: 10865355
Thats great, thanks.
Its funny how my mind was blank to go about it that way - even though I knew how.

Cheers
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

609 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