Problem with DataView and Find() method

  • Thread starter Thread starter Versteijn
  • Start date Start date
V

Versteijn

Hello all,

I have a method that constructs a dataset and sorts table 0 in it
through Table(0).DefaultView.Sort. I need to find a certain row in
this sorted dataview, and have the following code.

My problem is that I get an exception on the call to Find() telling me
it needs 2 values, but gets 3. While testing of my code shows that it
only provides 2 values.

Anyone has an idea? If there's an easier way to get what I want that
would be even greater! Thanks in advance.

The exception: Expecting 2 value(s) for the key being indexed, but
received 3 value(s).

My code:

Dim ds As DataSet = products.CreateDataSet(context, 2)
Dim dr As DataRow = ds.Tables(0).Rows.Find(ModelID)
Dim dv As DataView = ds.Tables(0).DefaultView
Dim k() As String = dv.Sort.Split(",")
Dim keys(k.Length) As Object
For i As Integer = 0 To k.Length - 1
Dim s As String = k(i)
s = s.Replace("DESC", "")
s = s.Trim()
If s.Length > 0 Then
keys(i) = dr(s)
End If
Next
Dim index As Integer = dv.Find(keys)
 
Versteijn,
Remember that in VB.NET arrays are zero based, that you define the upper
bound of the array, not the number of elements..

If k() has two elements, the following statement creates a 3 element array,
for elements 0, 1, 2.
Dim k() As String = dv.Sort.Split(",")
Dim keys(k.Length) As Object

Hope this helps
Jay
 
Back
Top