Seek method in a disconnected ADOR.Recorset ?

Hi,

I am trying to use the seek (ADO) method in some VBScript I am writing.

This is using a disconnected recordset where this is no database involved so please
keep that in mind.

Anyway I am wondering is it possible, if so what I am doing wrong in my code?

If this is not possible what is the next best thing the "Find" method?

Thanks,

Ward

' References:
'
' Recordset Object (ADO)
' http://msdn.microsoft.com/en-us/library/ms681510(VS.85).aspx
'
' Field Types:
' http://msdn.microsoft.com/en-us/library/ms675318(VS.85).aspx
'
' Filter Property:
' http://msdn.microsoft.com/en-us/library/ms676691(VS.85).aspx
'
' Seek Method:
' http://msdn.microsoft.com/en-us/library/ms675109(VS.85).aspx
'
' SeekEnum
' http://msdn.microsoft.com/en-us/library/ms681524(VS.85).aspx
'
' Hey, Scripting Guy! Stay Connected with Your Toaster
' http://technet.microsoft.com/en-us/magazine/cc743017.aspx
'
 
' Progress:   Create_Record_Set_ok
 
Function fnCreate_Record_Set
 
Const adVarChar = 200
Const MaxCharacters = 255
Const adFldIsNullable = 32
Const adInteger = 3
Const adSingle = 4
 
Const adSeekFirstEQ = 1
 
 
Dim supports_index
 
Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "Package_Details", adVarChar, MaxCharacters, adFldIsNullable
DataList.Fields.Append "Package_Index", adSingle, adFldIsNullable
 
supports_index = DataList.Supports(adIndex) 
WScript.Echo "Supports Index: " & supports_index
 
If supports_index = True Then
	DataList.Index = "Package_Index"
End if
 
 
DataList.Open
 
DataList.AddNew
DataList("Package_Details") = "Package 1"
DataList("Package_Index") = 3.0
DataList.Update
 
DataList.AddNew
DataList("Package_Details") = "Package 2"
DataList("Package_Index") = 2.9
DataList.Update
 
DataList.AddNew
DataList("Package_Details") = "Package 3"
DataList("Package_Index") = 2.8
DataList.Update
 
DataList.AddNew
DataList("Package_Details") = "Package 4"
DataList("Package_Index") = 2.75
DataList.Update
 
DataList.AddNew
DataList("Package_Details") = "Package 5"
DataList("Package_Index") = 3.12
DataList.Update
 
DataList.Sort = "Package_Index"
 
DataList.MoveFirst
 
Do While DataList.EOF = False
	WScript.Echo "Package Details: " & DataList.Fields.Item("Package_Details") & " Index: " & DataList.Fields.Item("Package_Index")
    DataList.MoveNext
Loop
 
' Test the Seek Function
'
 
Dim lookup_data
 
lookup_data = 2.8
' Returns an error:  Exception: Current provider does not support the necessary interface for Index functionality.
'
' *************************************************************
DataList.Seek Array(lookup_data), adSeekFirstEQ
 
If DataList.EOF Then
	WScript.Echo "** Not Found **"
Else
	WScript.Echo "Package Details (SEEK): " & DataList.Fields.Item("Package_Details") & " Index: " & DataList.Fields.Item("Package_Index")
End if
 
End Function
 
fnCreate_Record_Set

Open in new window

LVL 1
whorsfallAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Krys_KCommented:
Hi there
I have found that this is not possible with the type of recordset you are using. The notes below were found on this site

Note: This method can only be used with server-side cursors (not supported when the CursorLocation property value is adUseClient).
Note: This method can only be used when the Recordset object was opened with the CommandTypeEnum value of adCmdTableDirect.
I tried to use these on your sample code but with no luck i'm afraid.
Regards
Krystian
0
VoloxCommented:
Krystian is correct, you can only use the Seek method when you are using server side cursors with drivers that support this functionality.

You should use the Find method and if you need to find all the particular rows that meet a given set of criteria, then you will have to repeatedly call the find method.  I think the attached code will work as an example.


Dim lookup_data
 
lookup_data = "Package_Index = '2.8'"
DataList.MoveFirst
DataList.Find lookup_data
 
If DataList.EOF Then
	WScript.Echo "** Not Found **"
Else
	Do While Not DataList.EOF
		' In here you could form an array of absolute positions in the recordset
		' or you could count the number of finds or whatever you need to do
		WScript.Echo "Package Details (SEEK): " & DataList.Fields.Item("Package_Details") & " Index: " & DataList.Fields.Item("Package_Index")
		rstTitles.Find lookup_data, 1, adSearchForward
	Loop
End if

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.