Advantage Developer Zone


Using Advantage with Visual Studio 2005

Monday, October 15, 2007

With the release of Advantage 8.1 new support for the Visual Studio 2005 (VS2005) IDE was added. The Advantage .NET Data Provider now has support for Table Adapters and the Server Explorer. Support for these objects makes Advantage and VS2005 work together better.

Using the Server Explorer

The Server Explorer allows you to create connections to databases and view the objects contained within the database. Tables, views and stored procedures can all be viewed through the Server Explorer. Additionally, you can select fields from these objects and view their properties in the properties window.

To use the Server Explorer, you first need to create a connection to Advantage. You can connect to a folder containing free tables (ADT or DBF) or connect to a Data Dictionary. Clicking Connect to Database or choosing Add Connection from the Server Explorer context menu brings up the Add Connection dialog.

By default this will use the same provider that was used previously. It may prompt you to choose a provider if you have not previously created a connection. If Advantage Database Server is not specified as the Data source click the Change… button and choose the Advantage .NET Data Provider.

The Add Connection dialog allows you to set all of the various options for the Advantage Connection Object. You must specify the Data Source (path) for free connections. To connect to a data dictionary you must provide the path and name of the dictionary file (i.e. C:\Data\mydictionary.add). If your dictionary requires logins you must also provide a User ID and Password.

For more information about the other Advantage Connection options please refer to the Advantage Help File.

Once a connection has been created, a list of objects available through that connection will be visible in the Server Explorer. When the connection has been defined it will remain in the Server Explorer allowing connections to be used in many projects. The screen shots below show the available objects for a Data Dictionary connection ( left ) and a Free Table connection ( right ).


Creating a DataSet Object

Now that the connection to the data has been established it can be used to create typed datasets for your application. First add a DataSet object to your project. With the DataSet object open in the IDE you can simply drag and drop Tables, Views or Stored Procedures from the Server Explorer into it. The Advantage Designer will add the object schema to the DataSet and create a TableAdapter allowing the application to interact with the data.

The Advantage .NET Data Provider generates a SELECT, INSERT, UPDATE and DELETE statement for the TableAdapter. It also generates Table Mappings, Fill, Get and Update methods. These methods can now be used by various components and accessed through code.

NOTE: In order to be able to automatically generate UPDATE and DELETE statements, the table must have a primary key defined.

Additional methods can be added to the TableAdapter. These methods are created by adding another Query to the TableAdapter. This allows the developer to add ORDER BY and WHERE clauses to the SQL statements providing more flexibility in how the data is returned. Parameters may also be used in the SQL statement allowing the ability to query data based on user supplied values. The only restriction is that the new SQL statement must return the same fields defined in the Table Mappings.

Using the Data Sources Window

Now that the DataSet has been created and a table has been added it will be visible on the Data Sources tab. The Data Sources tab shows all of the DataSets in your project allowing you to drill-down into the tables, views and stored procedures that have been defined within the object.

The Data Sources tab contents are displayed differently based upon the active item in the IDE. If a DataSet is currently active, the Data Sources tab will indicate the data type for each field. When a WinForm is the active item the Data Sources tab will display a control type for each field. When a field is selected a drop-down allows you to specify a control type for the field.

After clicking on the table object, options for how to display data for the table can be selected. The table can be represented by either a DataGrid or as a detail form. The screen shot on the right shows the table with a detail form option selected.

With a WinForm active the table can be dragged onto the form. This will create all of the necessary controls on the form to display the data. The designer will create all of the necessary controls and bindings on the form for it to display the data from the object.

The generated form includes a binding navigator which provides buttons for moving through the data as well as inserting, updating and deleting records. This is all accomplished without writing a single line of code, which makes prototyping quick and easy. An example of this generated form with a few cosmetic changes is shown below.  JDM – I don’t see the image



With the Release of Advantage 8.1, creating Advantage based applications from VS2005 has become much easier. With the support for the Server Explorer, DataSets and Data Sources, rapid prototyping and robust separation of the data access layer is possible. Integration with these VS2005 features makes working with Advantage even easier.