The Data Source Web Component

Vertex42 The Excel Nexus

Professional Excel Templates

Get Instant Access

Unlike the other Office XP web components (Spreadsheet, Chart, and PivotTable), the Data Source web component is an ActiveX control without a user interface. Its main purpose is managing connections to the underlying data source and fetching records for display by other controls on a web page. This section demonstrates how to set up the Data Source control for providing data to a chart control. The next section in this appendix shows how to bind the Data Source control to a PivotTable.

You can use the Data Source control to connect to such databases as the SQL Server, Oracle, or Microsoft Access. To insert a Data Source web component on a web page, add an <OBJECT> tag and specify its class ID. The following statement places a Data Source control named dscl on an HTML page:

<object id=dsc1 classid=CLSID:0002E530-0000-0000-C000-000000000046></object>

Remember that the Data Source control has no visible interface at run time. To take advantage of this control, you must use the programming code to initialize it. After placing the <OBJECT> tag on a web page, specify the source for the data in the Data Source control. This is done by setting the control's ConnectionString property, as follows:

strConnection="Provider=Microsoft.Jet.OleDB.4.0; data source=" & _ "C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb" dsc1.ConnectionString = strConnection

Next, build the SQL query string to define the data that you want to retrieve from the database. This can be a simple query string like "SELECT * from Customers" or a more complex one like the one presented in the code section later in this section. To execute the query, add a recordset definition to the data source control by using the AddNew method of the RecordsetDefs collection:

Set rstdef = dsc1.RecordsetDefs.AddNew(strSQL, dsc1.Constants.dscCommandText)

The above statement says that you want to use the string specified by the first argument of the AddNew method (strSQL) for the new schema row source of type dscCommandText. Because VBScript does not understand enumerated constants, you need to precede the name of the second (optional) argument with the constant definition, like this: dscl.Con-stants.dscCommandText. The Data Source control can use table names, views, stored procedures, SQL statements, or XML files as the record row source. Each row source type is represented by a different enumerated constant (dscTable (1), dscView (2), dscCommandText (3), dscProcedure (4), and dscCommandFile (5)). You can add multiple recordset definitions to the Data Source control and specify in your code which recordset should be displayed.

After adding a recordset definition, use the Data Source property to bind your web control (Spreadsheet, Chart, or PivotTable) to the Data Source control:

ChrtSpace1.DataSource = dsc1

Because you can add multiple recordsets to the Data Source control, you should use the DataMember property to specify the name of the recordset that the specified control will get its data from:

ChrtSpace1.DataMember = rstdef.Name

The above statement sets the DataMember property of the Chart control to the created recordset. To find information on using the Chart web component, refer to the previous section.

Vdc Plc Battery Schematic

Was this article helpful?

0 0

Post a comment