ASP.NET Programmer's Reference
WordTemplate.SetDataSource Method |
 |
SetDataSource(Values as Object Array, Fields as String Array)
C# Syntax:
public int WordTemplate.SetDataSource(object[] values, string[] names);
VB.NET Syntax:
Public Function WordTemplate.SetDataSource(values As Object(), names As String()) As Integer
Description:
Sets a template's data source to a one-dimensional object array. This method
takes an object array of values and a string array of field names. The two
arrays must contain the same number of elements. Each name in the array of field
names must be the same as the corresponding merge field name in the template.
Each merge field in a WordWriter template must bind to a data source field/value pair.
The number of merge fields in the template may not exceed the number of values in the
data source. However, the number of values in the data source may be greater than the
number merge fields in the template.
In WordWriter 1.0, a template can have only one data source. Do not
call SetDataSource more than once for a single instance of WordTemplate.
|
Parameters:
- object[]
An object array of values to use as a data source. WordWriter
will insert these values in the template's merge fields.
- string[]
A string array of data source field names. These must be the same
as the corresponding merge field names in the template
Exceptions:
-
System.ArgumentException

SetDataSource will throw this exception if the object array
and field name array passed to the method do not contain the
same number of elements.
-
System.ArgumentNullException

SetDataSource will throw this exception if null (C#)
or Nothing (VB.NET) is passed to the method.
Example:
[VB.NET]
'--- Create a string array of field names.
'--- The field names must be the same as the merge field
'--- names in the template.
Dim arrFields As String() = {"CompanyName", _
"StreetAddr", _
"City", _
"State", _
"ZipCode"}
'--- Create an object array of values
'--- Ordinal numbers match those of the fields array
Dim arrValues As Object() = {"SoftArtisans", _
"1330 Beacon Street", _
"Brookline", _
"MA", _
"02446"}
oWW.SetDataSource(arrValues, arrFields)
Top
SetDataSource(DataSet)
C# Syntax:
public int WordTemplate.SetDataSource(System.Data.DataSet);
VB.NET Syntax:
Public Function WordTemplate.SetDataSource(System.Data.DataSet) As Integer
Description:
Sets a template's data source to an ADO.NET DataSet. A DataSet contains a collection
of DataTables. If you set a template's data source to a DataSet, WordWriter will get the
first row of the first DataTable in the DataSet.
The DataSet object is in the System.Data namespace. Use an
Import directive to import the namespace to the aspx page:
<%@ Import namespace="System.Data" %>
In WordWriter 1.0, a template can have only one data source. Do not
call SetDataSource more than once for a single instance of WordTemplate.
|
Parameters:
- DataSet
An ADO.NET DataSet to use as the template's data source. WordWriter will
use the first row of the first DataTable in the DataSet as the data source.
Exceptions:
Example:
[VB.NET]
Dim oConn As OleDbConnection
Dim oAdpt As OleDbDataAdapter
Dim oDS As DataSet
Dim oWW As WordWriter
oWW = New WordTemplate()
oWW.Open(Server.MapPath(Application("vroot").ToString() + _
"templates/databasetemplate1.doc"))
Dim strSQL As String = String.Format("SELECT LastName, FirstName, TitleOfCourtesy,_
Address, City, Region, PostalCode " + _
"FROM Employees WHERE EmployeeID={0}", _
employeeSelect.SelectedItem.Value.ToString())
'--- Open an OLEDB connection.
oConn = New OleDbConnection(strConnString)
oConn.Open()
'--- Create an instance of the OleDbDataAdapter
'--- object.
oAdpt = New OleDbDataAdapter(strSQL, oConn)
'--- Create a DataSet and fill it with the data
'--- returned by the SQL database query.
oDS = New DataSet()
oAdpt.Fill(oDS)
'--- Pass the DataSet to setDataSource. WordWriter
'--- will use the first DataTable in the DataSet as
'--- the data source.
oWW.SetDataSource(oDS)
Top
SetDataSource(DataTable)
C# Syntax:
public int WordTemplate.SetDataSource(System.Data.DataTable);
VB.NET Syntax:
Public Function WordTemplate.SetDataSource(System.Data.DataTable) As Integer
Description:
Sets a template's data source to an ADO.NET DataTable. If the specified
DataTable contains more than one row, WordWriter will use the first row as
the data source.
The DataTable object is in the System.Data namespace. Use an
Import directive to import the namespace to the aspx page:
<%@ Import namespace="System.Data" %>
In WordWriter 1.0, a template can have only one data source. Do not
call SetDataSource more than once for a single instance of WordTemplate.
|
Parameters:
- DataTable
An ADO.NET DataTable to use as the data source.
WordWriter will use the first row of the
DataTable as the data source.
Exceptions:
Example:
[VB.NET]
'--- Instantiate and open an OleDbConnection, passing the connection string.
oConn = New OleDbConnection(strConnString)
oConn.Open()
'--- Instantiate an OleDbDataAdapter.
oAdpt = New OleDbDataAdapter(strSQL, oConn)
'--- Instantiate and populate DataSet.
oDS = New DataSet()
oAdpt.Fill(oDS, "myDataTable")
'--- Get a DataTable from the DataSet.
oDT = oDS.Tables("myDataTable")
'--- Instantiate the WordTemplate object.
oWW = New WordTemplate()
'--- Call Open() to open the template file.
oWW.Open(Server.MapPath("./DataTableTemplate.doc"))
'--- Pass the DataTable object to SetDataSource().
oWW.SetDataSource(oDT)
'--- Call Process() to populate the template with the new data.
oWW.Process()
oWW.Save(Page.Response, "DataTableOutput.doc", False)
Top
Copyright © 2003, SoftArtisans, Inc.