Working with a DataStore

To use a DataStore, you first need to create an instance of the DataStore object and assign the DataWindow object to the DataStore. You can do this using drag-and-drop, as described for DataWindowControls in “Adding DataWindows to a form”, or in code.

Because it is a nonvisual object, when you drag a DataStore onto a form, its icon displays below the form. Also because it is nonvisual, it has only a few properties you need to set, including the LibraryList and DataWindowObject.

Then, if the DataStore is intended to retrieve data, you need to set the transaction object for the DataStore and connect to the database, if there is no existing connection. Once these setup steps have been performed, you can retrieve data into the DataStore, share data with another DataStore or DataWindow control, or perform other processing.

Examples

The following code shows the code generated when you drag a DataStore onto a Windows form in a C# project and set its LibraryList and DataWindowObject properties.

Notice that a BeginInit method was generated. The Visual Studio .NET design environment uses this method to start the initialization of a component that is used on a form or used by another component. The EndInit method ends the initialization. Using the BeginInit and EndInit methods prevents the control from being used before it is fully initialized:

[C#]
// In the declaration block for Form1
private Sybase.DataWindow.DataStore dsDept;
...
// In private void InitializeComponent()
this.dsDept = new
   Sybase.DataWindow.DataStore(this.components);
((System.ComponentModel.ISupportInitialize)
   (this.dsDept)).BeginInit();
...
//
this.dsDept.LibraryList = "C:\\dwbexam.pbl";
this.dsDept.DataWindowObject = "printer_sales";