Sorting a Dataview and Finding

  • Thread starter Thread starter Charles A. Lackman
  • Start date Start date
C

Charles A. Lackman

Hello
I have created a Dataview and have sorted it on the Date and ShiftNumber
columns
this works great, but when I want to use the Find Method it gives me the
following error:
Expecting 2 value(s) for the key being indexed, but received 1 value(s).

I have tried the following:

Dim Names(1) as Object
Name(0) = TheDate
Name(1) = txtShiftNumber.text
X = ADataView.Find(Names)

and

X = ADataview.Find(TheDate)

Any assistance will be greatly appeciated.
Thank,
Chuck
 
Hi,

You need to enclose the date in #. Try this.

Dim Names(1) as String
Name(0) = string.format("#{0}#",TheDate)
Name(1) = txtShiftNumber.text
X = ADataView.Find(Names)

Ken
-------------------
Hello
I have created a Dataview and have sorted it on the Date and ShiftNumber
columns
this works great, but when I want to use the Find Method it gives me the
following error:
Expecting 2 value(s) for the key being indexed, but received 1 value(s).

I have tried the following:

Dim Names(1) as Object
Name(0) = TheDate
Name(1) = txtShiftNumber.text
X = ADataView.Find(Names)

and

X = ADataview.Find(TheDate)

Any assistance will be greatly appeciated.
Thank,
Chuck
 
Thank You for you assistance but it did not work, I received an invalid cast
exception.

I am sorting the Dataview on two columns, I believe this is why it is
requiring two arguments for the sort. But when I try to give the Find to
arguments it underlines it.

I am sorting as such:
ADataView = New DataView(ADataset.Tables("Temp"))
ADataView.sort = "Date, Shift"

If I do not sort and Date and Shift It works just fine Finding the Date:

X = ADataview.Find(TheDate)

It's the 2 parameters that is giving me the problem.

Chuck
 
Charles,

You have to decide which methode you use.
For the "find: you need to add or have a primary key to your datatable.

http://msdn.microsoft.com/library/d...systemdatadatarowcollectionclassfindtopic.asp

You can as well use the dataview.rowfilter and the datatable.select
http://msdn.microsoft.com/library/d...rlrfSystemDataDataViewClassRowFilterTopic.asp

Or the datatable select
http://msdn.microsoft.com/library/d.../frlrfSystemDataDataTableClassSelectTopic.asp

I hope this helps?

Cor

"Charles A. Lackman" <
 
Back
Top