ADO Data Environment

ADO Data Environment

Visual Basic 6 introduced the ADO data environment, which provides a visual way to add and edit data objects. With the ADO Data Environment Designer, you can add connections, commands, and child commands. At run time, the ADO data environment acts like a class, with collections of connections, commands, and Recordsets.

Because Visual Basic .NET does not support the ADO data environment, the Upgrade Wizard upgrades data environments to a class that has the same run-time behavior. Since it s a class, not an ADO data environment, the editing experience is less rich than in Visual Basic 6. The programming model for the upgraded class is almost identical to Visual Basic 6. For example, suppose your project has a data environment named myDataEnvironment, with a command called myCommand. The following code would assign a Recordset to the result of the command:

Dim rs As Recordset Set rs = myDataEnvironment.rsmyCommand

After upgrading, this code looks like the following:

Dim rs As ADODB.Recordset rs = myDataEnvironment.rsmyCommand

With a few exceptions that we will discuss now, the upgraded data environment behaves like the original Visual Basic 6 version.

Calling Dispose

When your application shuts down, it s important to dispose of the upgraded ADO data environment. This closes all Recordsets, commands, and connections. To dispose of the ADO data environment, call the Dispose method. For example, suppose your application has an ADO data environment named DataEnvironment1. You would dispose of it with the following line of code:

DataEnvironment1.Dispose

You should put this line somewhere in your application shutdown code.

Initialize Event

In Visual Basic 6, the ADO data environment supports an Initialize event and a Finalize event. When your application is upgraded, the code in these events is upgraded, but as procedures. The events won t be fired when the application is run. You should move the code in the Initialize procedure into the New event and the code in the Finalize procedure into the Dispose event.

Cursor Location with Microsoft Access Databases

In Visual Basic 6, you could set the cursor location of an ADO connection object to adUseServer or adUseClient, signifying a server-side or client-side cursor location, respectively. If the database is a Microsoft Access database, the property is ignored and a client-side cursor is always used. In Visual Basic .NET, trying to use a server-side cursor with a Microsoft Access database causes a run-time exception, since the value is invalid. This situation may cause problems in upgraded applications if you have inadvertently set the cursor to be server-side. The solution is to remove the line of code in the Visual Basic .NET project that sets the cursor location. For example,

Me.Adodc1.CursorLocation = ADODB.CursorLocationEnum.adUseServer

This rule applies to the ADO data environment, the ADO Data control, and connections created in code.



Upgrading Microsoft Visual Basic 6.0to Microsoft Visual Basic  .NET
Upgrading Microsoft Visual Basic 6.0 to Microsoft Visual Basic .NET w/accompanying CD-ROM
ISBN: 073561587X
EAN: 2147483647
Year: 2001
Pages: 179

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net