Condividi tramite


Visual Basic Concepts

Data Sources Recap

The preceding topics demonstrated how easy it is to create data source components — first as an ActiveX control, then as an ActiveX DLL. Those aren't the only options either. You could just as easily create an ActiveX EXE data source, or simply use a data-aware class as a data source. So how do you decide? There aren't any hard and fast rules, but here are a few suggestions:

  • Use a data-aware class when you don't anticipate that you'll need to reuse a data source — for example, to access data that keeps track of scores for a game.

  • Use an ActiveX DLL when you need a data source that doesn't require a visual interface and that runs in-process. An example of this might be a component that supplies stock quotes to be displayed in another control or in a spreadsheet. Such a component can easily be reused in different applications.

  • Use an ActiveX EXE for a data source that needs to run out-of-process, such as a middle-tier component that enforces business rules against a back-end database. An ActiveX EXE can also be reused in different applications.

  • Use an Active X control when you need a visual interface for your data source. The obvious example for this is the Data control; however, you might also want to combine the display interface as a part of your data source by using a grid, chart, or group of text boxes. Of course, ActiveX controls can also easily be shared and distributed.

In addition to choosing the type of data source, you also have a lot of flexibility when it comes to choosing a data interface. As demonstrated in the preceding topics, you can easily switch between OLE DB and ODBC data source using just about any database as a back-end.

Perhaps the most intriguing option is the OLE DB Simple Provider. The example demonstrated the use of a simple text file as a data source, but that's just the tip of the iceberg. With OSP, you have complete control over how and where the data is stored. You can create your own custom file formats, storing data in a binary format that only your component can read. You could even use an OSP component to store and retrieve objects.

With all the possibilities, one thing is certain — data source components elevate data binding to a whole new level.

Step by Step

This topic is the final topic in a series that walks you through creating sample ActiveX data sources.

To See
Start from the beginning Creating Data Sources