Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0
Description

Excerpt

Sets a main document data source to a one-dimensional object array. The method imports a single row of data to the specified set of main document merge fields.

Signature
C#C#
Wiki Markup
{description}
{excerpt}Sets a main document data source to a one\-dimensional object array. The method imports a single row of data to the specified set of main document merge fields.
{excerpt}
{signature:C#}
 public void SetDataSource(System.Object[] dataRow, System.String[] fieldNames)
Signature
{signature}
{signature:vb.net
vb.net
}
Public Sub SetDataSource(ByVal dataRow As Object(), ByVal fieldNames As String())
Parameters

...

An object array of values to use as a data source. WordWriter will insert these values in the template's merge fields.

...

A string array of data source field names. These must be the same as the corresponding merge field names in the template

Exceptions

...

Save will throw this exception if null (C#) or Nothing (VB.NET) is passed to the method.

...

Remarks

SetDataSource 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 a set (merge fields that share the same data source name or number) may not exceed the number of values in the data source defined by SetDataSource. However, the number of values in the data source may be greater than the number of merge fields in the set.

This method may be called once for each set of merge fields in the main document.

{signature}
{parameters}
{param:data}An object array of values to use as a data source. WordWriter will insert these values in the template's merge fields.
{param}
{param:fieldNames}A string array of data source field names. These must be the same as the corresponding merge field names in the template
{param}
{exceptions}
{exception:ArgumentNullException}[Save|WordTemplate.Save] will throw this exception if {{null}} \(C\#\) or {{Nothing}} \(VB.NET\) is passed to the method.
{exception}
{exception:ArgumentException}
{exception}
{remarks}[SetDataSource|WordTemplate.SetDataSource] 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 a set \(merge fields that share the same data source name or number\) may not exceed the number of values in the data source defined by {{SetDataSource}}. However, the number of values in the data source may be greater than the number of merge fields in the set.

This method may be called once for each set of merge fields in the main document.

{remarks}
{example}{code:csharp|title=C#}

          //--- Create a string array of field names.
          //--- The field names must be the same as the merge field
          //--- names in the template.
          string[] arrFields = {"CompanyName",
               "StreetAddr",
               "City",
               "State",
               "ZipCode"};

          //--- Create an object array of values
          //--- Ordinal numbers match those of the fields array
          object[] arrValues = {"SoftArtisans",
               "1330 Beacon Street",
               "Brookline",
               "MA",
               "02446"};
          oWW.SetDataSource(arrValues, arrFields);
        
{code}
{code:vb.net
|title=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)
        {code}

{example}
Example
Code Block
csharpcsharp
titleC#
Code Block
vb.nettitle