Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Data Source Objects and RDS

Status
Not open for further replies.

Jorgandr

Programmer
May 10, 2002
58
US
Has anyone added a Data Source Object to their page? I'm trying to figure out how to display field names, information etc.. the code below will display the records but how do you go about manipulating the data like you would with a Record Set?

<HTML>
<HEAD>
<META HTTP-EQUIV=&quot;Content-Type&quot; Content=&quot;text-html; charset=Windows-1252&quot;>
<TITLE>Datasheet view</TITLE>
</HEAD>
<BODY>
<TABLE id=&quot;Table&quot; datasrc=&quot;#DSO&quot; datapagesize=&quot;10&quot;>
<TR>
<TD><SPAN datafld=&quot;Project ID&quot;></SPAN></TD>
<TD><SPAN datafld=&quot;Person Requesting&quot;></SPAN></TD>
<TD><SPAN datafld=&quot;Project Leader&quot;></SPAN></TD>
</TR>
<TFOOT>
<TR>
<TD colspan=&quot;2&quot;>
<TABLE>
<TR>
<TD><BUTTON onclick=&quot;Table.firstPage();&quot;>First Page</BUTTON></TD>
<TD><BUTTON onclick=&quot;Table.previousPage();&quot;>Previous Page</BUTTON></TD>
<TD><BUTTON onclick=&quot;Table.nextPage();&quot;>Next Page</BUTTON></TD>
<TD><BUTTON onclick=&quot;Table.lastPage();&quot;>Last Page</BUTTON></TD>
</TR>
</TABLE>
</TD>
</TR>
</TFOOT>
</TABLE>
<!-- RDS.DataControl -->
<%SQL=&quot;SELECT * FROM [PCSD Projects] WHERE [Project ID Year]='02'&quot;%>
<OBJECT classid=&quot;clsid:BD96C556-65A3-11D0-983A-00C04FC29E33&quot; id=&quot;DSO&quot; width=&quot;0&quot; height=&quot;0&quot;>
<PARAM name=&quot;Connect&quot; value=&quot;DSN=CCC Tracking&quot;>
<PARAM name=&quot;Server&quot; value=&quot; <PARAM name=&quot;SQL&quot; value=&quot;<%=SQL%>&quot;>
</OBJECT>
</BODY>
</HTML>
 
I have never used the Data Source Object because I prefer to bring the recordset over to the client and work with ADO. However, you might find some help using the MSOWCVBA.CHM help file, if you haven't found it already.

Have you read the MSPress book, Programming Office Web Components?
 
Normally I would, however the project I am working with uses a database on a different server than the others. For some reason the IT People can not create a normal DSN that will allow me to use ADO. It doesn't make much sense to me but that's what they say.
 
I found this code example for working with the data source control. It uses Northwind.MDB

<html>

<head>
<meta name=&quot;GENERATOR&quot; content=&quot;Microsoft FrontPage 4.0&quot;>
<meta name=&quot;ProgId&quot; content=&quot;FrontPage.Editor.Document&quot;>
<title>DSC Example Page</title>
<link rel=&quot;STYLESHEET&quot; href=&quot;../Styles/OWCStyle.css&quot; type=&quot;text/css&quot;>

<!-- DataSoure Control -->
<object classid=&quot;clsid:0002E530-0000-0000-C000-000000000046&quot; id=&quot;DSC&quot;>
</object>
</head>

<body>

<h1>DSC Example Page</h1>
<p>Show only the following countries: <input type=&quot;text&quot; id=&quot;txtCountries&quot;
size=&quot;40&quot; value=&quot;USA, Canada, Mexico&quot;>&nbsp;&nbsp; <input type=&quot;button&quot;
value=&quot;Go&quot; id=&quot;btnFilter&quot;></p>

<!-- Chart Control -->
<object classid=&quot;clsid:0002E500-0000-0000-C000-000000000046&quot; id=&quot;ChartSpace1&quot;
style=&quot;width:100%;height:75%&quot; width=&quot;576&quot; height=&quot;384&quot;>
</object>

<!-- Script for loading the chart -->
<script language=VBScript>
'--------------------------------------------------------------------------
' Window_onLoad()
'
' Purpose: Runs when the page is first loaded in the browser. Code
' here will set the connection info for the DSC and add a
' RecordsetDef object as a source of data for the Chart.
'
Sub Window_onLoad()
' Set the DSC's ConnectionString property.
' Note: Change this line if you move the MDB file or want to connect to
' a different MDB file.
sDBPath = &quot;..\Data\Northwind.mdb&quot;
DSC.ConnectionString = _
&quot;provider=microsoft.jet.oledb.4.0;data source=&quot; & sDBPath

' Add a RecordsetDef object that will be a
' row source for the Chart control
set rsdef = DSC.RecordsetDefs.AddNew(&quot;SELECT Country, &quot; & _
&quot;Shippers.CompanyName AS Shipper, &quot; & _
&quot;Count(*) AS Shipments, &quot; & _
&quot;Sum(Quantity) AS Quantity &quot; & _
&quot;FROM Invoices &quot; & _
&quot;WHERE OrderDate Between #1/1/98# &quot; & _
&quot;and #12/31/98# &quot; & _
&quot;GROUP BY Country, Shippers.CompanyName&quot;, _
DSC.Constants.dscCommandText, &quot;ChartData&quot;)

' Add a calculated field to the RecordsetDef object
rsdef.PageFields.Add &quot;[Quantity]/[Shipments]&quot;, _
DSC.Constants.dscCalculated, &quot;AvgQtyPerShipment&quot;

' Add another RecordsetDef object to show using a named view
' and the ServerFilter proprety
set rsdef = DSC.RecordsetDefs.AddNew(&quot;Invoices&quot;, _
DSC.Constants.dscView, &quot;ChartData2&quot;)

rsdef.ServerFilter = &quot;OrderDate Between #1/1/98# and #1/31/98#&quot;

BindChartToDSC Chartspace1, DSC, &quot;ChartData&quot;, &quot;Shipper&quot;, _
&quot;Country&quot;, &quot;AvgQtyPerShipment&quot;

' Label the value axis of the chart
set c = ChartSpace1.Constants
set ax = ChartSpace1.Charts(0).Axes(c.chAxisPositionBottom)
ax.HasTitle = True
ax.Title.Caption = &quot;Average Quantity per Shipment&quot;
ax.Title.Font.Size = 8

End Sub 'Window_onLoad()

'--------------------------------------------------------------------------
' BindChartToDSC()
'
' Purpose: Binds a chart to a Recordset in the DSC. (This example creates
' a Pie chart.)
' In: cspace reference to the ChartSpace object
' dsc reference to the Data Source control
' sRSName name of RecordsetDef in the DSC to which we will bind
' sSeries name of the result column containing series
' sCategories name of the result column containing categories
' sValues name of the result column containing values
'
Sub BindChartToDSC(cspace, dsc, sRSName, sSeries, sCategories, sValues)
' Local variables
Dim cht ' Chart object we'll create in the chart space

' Grab the Constants object so we can use constant names in the script.
' Note: This is only needed in VBScript. Do not use this in VBA code.
set c = cspace.Constants

' Clear out anything that is in the chart space
cspace.Clear

' First tell the chart that its data is coming from the DSC
set cspace.DataSource = dsc

' Next tell it what Recordset object within the DSC it will bind to
cspace.DataMember = sRSName

' Create a (Pie) chart in the chart space
set cht = cspace.Charts.Add()
cht.HasLegend = True
cht.Type = c.chChartTypeBarClustered

' Now call SetData to bind the various dimensions.
' Second parameter is zero, meaning use the first data source
' if there is more than one
cht.SetData c.chDimSeriesNames, 0, sSeries
cht.SetData c.chDimCategories, 0, sCategories
cht.SetData c.chDimValues, 0, sValues

End Sub 'BindChartToDSC()

'--------------------------------------------------------------------------
' btnFilter Click Event Handler
'
' Purpose: Runs whenever the Filter button is clicked. Gets the Recordset
' object the chart is bound to and filters for only the specified
' countries.
Sub btnFilter_onClick()
' Local variables
Dim rs ' Recordset object
Dim asCountries ' String array of country names
Dim sFilter ' Filter expression
Dim ct ' Counter

' Get the Recordset object the chart is bound to
Set rs = DSC.Execute(ChartSpace1.DataMember)

' Get the set of country names to filter on
asCountries = Split(txtCountries.value,&quot;,&quot;)

' Build the filter expression
on error resume next
sFilter = &quot;Country='&quot; & Trim(asCountries(0)) & &quot;'&quot;
if err.Number = 0 then
For ct = 1 To Ubound(asCountries)
sFilter = sFilter & &quot; OR Country='&quot; & _
Trim(asCountries(ct)) & &quot;'&quot;
Next 'ct
else
sFilter = &quot;&quot;
end if

' Now set the filter expression.
' The chart will automatically update.
rs.Filter = sFilter
End Sub 'btnfilter_onClick()

Sub txtCountries_onKeyDown()
if window.event.keyCode = 13 then ' Enter key
btnFilter_onClick
end if
End Sub

</script>

</body>

</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top