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.
public void SetDataSource(System.Data.DataTable dt)
Public Sub SetDataSource(ByVal dt As System.Data.DataTable)
Parameters
dt
An ADO.NET DataTable to use as the data source. WordWriter will use the first row of the DataTable as the data source.Exceptions
ArgumentNullException
Save will throw this exception ifnull (C#) or Nothing (VB.NET) is passed to the method.
ArgumentException
Remarks
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 of merge fields in the template.
Do not call this method more than once for a single instance of WordTemplate. To set multiple 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)
Examples
WordTemplate oWW = new WordTemplate();
oWW.Open(@"c:\temp\template.doc");
string strSQL = "SELECT LastName, FirstName, TitleOfCourtesy, " +
"Address, City, Region, PostalCode " +
"FROM Employees WHERE EmployeeID=1";
//--- Create an OLEDB connection.
OleDbConnection oConn = new OleDbConnection(strConnString);
//--- Create an instance of the OleDbDataAdapter
//--- object.
OleDbDataAdapter oAdpt = new OleDbDataAdapter(strSQL, oConn);
//--- Create a DataTable and fill it with the data
//--- returned by the SQL database query.
DataTable oDT = new DataTable();
oAdpt.Fill(oDT);
//--- Pass the DataTable to SetDataSource.
oWW.SetDataSource(oDT);
Dim oWW As New WordTemplate()
oWW.Open("c:\temp\template.doc")
Dim strSQL As String = "SELECT LastName, FirstName, " & _
"TitleOfCourtesy, Address, City, Region, PostalCode " & _
"FROM Employees WHERE EmployeeID=1"
'--- Create an OLEDB connection.
Dim oConn As New OleDbConnection(strConnString)
'--- Create an instance of the OleDbDataAdapter
'--- object.
Dim oAdpt As New OleDbDataAdapter(strSQL, oConn)
'--- Create a DataTable and fill it with the data
'--- returned by the SQL database query.
Dim oDT As New DataTable()
oAdpt.Fill(oDT)
'--- Pass the DataTable to SetDataSource.
oWW.SetDataSource(oDT)
