Message-ID: <1075796320.8761.1711659632861.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_8760_1850091719.1711659632861" ------=_Part_8760_1850091719.1711659632861 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html WordTemplate.SetDataSource(System.Data.IDataReader)

WordTemplate.SetDataSource(System.Data.IDataReader)

Description

=20

Sets a template's data source to an an IDataReader interface, which may = be either a SqlDataReader, OleDbDataReader or an AdomdDataReader. If the sp= ecified DataReader returns more than one row, WordWriter will use the first= row as the data source.

=20
C#
=20
 public void SetDataSource(System.Data.IDataReader dr)
=20
=20
vb.net
=20
Public Sub SetDataSource(ByVal dr As System.Data.IDataReader)
=20
=20

P= arameters

=20
dr
A= SqlDataReader, OleDbDataReader or an AdomdDataReader to use as the data so= urce. WordWriter will use the first row of the DataReader as the data sourc= e.=20

E= xceptions

=20
ArgumentNullException
=20 Save will t= hrow this exception if=20 null (C#) or=20 Nothing (VB.NET) is passed to the method.=20
ArgumentException
=20

Rema= rks

=20

Each merge field in a WordWriter template must bind to a data source fie= ld/value pair. The number of merge fields in the template may not exceed th= e number of values in the data source. However, the number of values in the= data source may be greater than the number of merge fields in the template= .

=20

Do not call this method more than once for a single instance of WordTemplate. To set mu= ltiple main document data sources, use the following methods:
SetDataSource(Object(), String(), String)
SetDataSource(System.Data.DataSet, String)
SetDataSource(System.Data.DataTable, String)
SetDataSource(System.Data.IDataReader, String)

= =20

Exa= mples

=20
C#
=20

          WordTemplate oWW =3D new WordTemplate();
          oWW.Open(@"c:\temp\template.doc");
          string strSQL =3D "SELECT LastName, FirstName, " +
               "TitleOfCourtesy, Address, City, Region, PostalCode &qu=
ot; +
               "FROM Employees WHERE EmployeeID=3D1";

          //--- Create an OLEDB connection.
          OleDbConnection oConn =3D new OleDbConnection(strConnString);

          //--- Create an OleDbCommand
          OleDbCommand oCmd =3D new OleDbCommand(strSQL, oConn);

          //--- Get an OleDbDataReader
          oConn.Open();
          OleDbDataReader oReader =3D
               oCmd.ExecuteReader(CommandBehavior.CloseConnection);

          //--- Pass the DataReader to SetDataSource.
          oWW.SetDataSource(oReader);

          //--- Close the reader (should do this in a finally block)
          oReader.Close();
          ...
        
=20
=20
vb.net
=20

          Dim oWW As New WordTemplate()
          oWW.Open("c:\temp\template.doc")
          Dim strSQL As String =3D "SELECT LastName, FirstName, "=
 & _
               "TitleOfCourtesy, Address, City, Region, PostalCode &qu=
ot; & _
               "FROM Employees WHERE EmployeeID=3D1"

          '--- Create an OLEDB connection.
          Dim oConn As New OleDbConnection(strConnString)

          '--- Create an OleDbCommand
          Dim oCmd As New OleDbCommand(strSQL, oConn)

          '--- Get an OleDbDataReader
          oConn.Open()
          Dim oReader As OleDbDataReader =3D _
               oCmd.ExecuteReader(CommandBehavior.CloseConnection)

          '--- Pass the DataReader to SetDataSource.
          oWW.SetDataSource(oReader)

          '--- Close the reader (should do this in a finally block)
          oReader.Close()
          ...
        
=20
------=_Part_8760_1850091719.1711659632861--