Solved

ADODC Control + Index

Posted on 2003-11-26
8
540 Views
Last Modified: 2013-12-25
Hello

Is It possible to change the Index of a table wich is linked to an ADODC control ?
If yes, how can I change it ?

Thanks

Fabian
0
Comment
Question by:PROMISYS
8 Comments
 
LVL 29

Expert Comment

by:leonstryker
ID: 9824490
PROMISYS,

It should be possible, but not by using ADODC.  What database are you using in the backend?  

May I suggest you not use ADODC at all.  It will make your life a lot easier.

Leon
0
 

Author Comment

by:PROMISYS
ID: 9824884
It's an Access Database.

I first try to use DAO but, I got some problems when
more than one user use the program ...
0
 
LVL 29

Assisted Solution

by:leonstryker
leonstryker earned 200 total points
ID: 9824914
The way to go is by using ADO directly.

Remove the control.  Declare a Connection object (globally) and Recordset object (locally)

Public cnConn As ADODB.Connection

Dim rsRecSet As ADODB.Recordset

You may then bind your recordset to whatever you want such as:

Set dgrGrid.DataSource = rsRecSet

Leon
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 8

Expert Comment

by:MYLim
ID: 9830496
0
 
LVL 8

Accepted Solution

by:
MYLim earned 200 total points
ID: 9830601
Seek Method and Index Property Example (VB)
This example uses the Recordset object's Seek method and Index property in conjunction with a given Employee ID, to locate the employee's name in the Employees table of the Nwind.mdb database.

'BeginSeekVB
Public Sub SeekX()
Dim rst As ADODB.Recordset
Dim strID As String
Dim strPrompt As String
strPrompt = "Enter an EmployeeID (e.g., 0 to 9)"

Set rst = New ADODB.Recordset
rst.CursorLocation = adUseServer
rst.Open "employees", _
            "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=E:\Program Files\Microsoft Office\Office\Samples\northwind.mdb;" & _
            "user id=admin;password=;", _
            adOpenKeyset, adLockReadOnly, adCmdTableDirect

' Does this provider support Seek and Index?
If rst.Supports(adIndex) And rst.Supports(adSeek) Then
    rst.Index = "PrimaryKey"
    ' Display all the employees.
        rst.MoveFirst
        Do While rst.EOF = False
            Debug.Print rst!EmployeeId; ": "; rst!firstname; " "; _
                rst!LastName
            rst.MoveNext
        Loop
   
' Prompt the user for an EmployeeID between 0 and 9.
      rst.MoveFirst
      Do
         strID = LCase(Trim(InputBox(strPrompt, "Seek Example")))
         ' Quit if strID is a zero-length string (CANCEL, null, etc.)
         If Len(strID) = 0 Then Exit Do
         If Len(strID) = 1 And strID >= "0" And strID <= "9" Then
            rst.Seek Array(strID), adSeekFirstEQ
            If rst.EOF Then
               Debug.Print "Employee not found."
            Else
               Debug.Print strID; ": Employee='"; rst!firstname; " "; _
               rst!LastName; "'"
            End If
         End If
      Loop
End If

rst.Close
End Sub
'EndSeekVB

0
 
LVL 8

Expert Comment

by:MYLim
ID: 9830604
http://doc.ddart.net/mssql/sql2000/html/mdacxml/htm/mdproindex.htm
ADO API Reference  

Index Property
Indicates the name of the index currently in effect for a Recordset object.

Settings and Return Values
Sets or returns a String value, which is the name of the index.

Remarks
The index named by the Index property must have previously been declared on the base table underlying the Recordset object. That is, the index must have been declared programmatically either as an ADOX Index object, or when the base table was created.

A run-time error will occur if the index cannot be set. The Index property cannot be set:

Within a WillChangeRecordset or RecordsetChangeComplete event handler.
If the Recordset is still executing an operation (which can be determined by the State property).
If a filter has been set on the Recordset with the Filter property.
The Index property can always be set successfully if the Recordset is closed, but the Recordset will not open successfully, or the index will not be usable, if the underlying provider does not support indexes.

If the index can be set, the current row position may change. This will cause an update to the AbsolutePosition property, and the generation of WillChangeRecordset, RecordsetChangeComplete, WillMove, and MoveComplete events.

If the index can be set and the LockType property is adLockPessimistic or adLockOptimistic, then an implicit UpdateBatch operation is performed. This releases the current and affected groups. Any existing filter is released, and the current row position is changed to the first row of the reordered Recordset.

The Index property is used in conjunction with the Seek method. If the underlying provider does not support the Index property, and thus the Seek method, consider using the Find method instead. Determine whether the Recordset object supports indexes with the Supports(adIndex) method.

The built-in Index property is not related to the dynamic Optimize property, although they both deal with indexes.

0
 
LVL 1

Expert Comment

by:ayufans
ID: 10512129
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points split between leonstryker and MYLim

Please leave any comments here within the next four days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

ayufans
Cleanup Volunteer
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now