Message-ID: <1112644709.8949.1711668970934.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_8948_137677904.1711668970934" ------=_Part_8948_137677904.1711668970934 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html ExcelTemplate.BindData(System.Data.DataView, String, DataBinding= Properties)

ExcelTemplate.BindData(System.Data.DataView, String, DataBindingPro= perties)

Introduced in build 9.1

=20

Description

Sets an ADO.NET DataView as a data source to bind to template data m= arkers.=20
C#
=20
 public virtual void BindData(System.Data.DataV=
iew source, System.String dataSourceName, DataBindingProperties property)
=20
=20
vb.net
=20
Public Overridable Sub BindData(ByVal source As =
System.Data.DataView, ByVal dataSourceName As String, ByVal [property] As D=
ataBindingProperties)
=20

Parameters

=20
source
The DataView to use as the data source.=20
dataSourceName
The name of the set of data ma= rkers at which to insert the values imported from the data source.=20 dataSourceName must be specified, but can be left as null or a= n empty string if this is the first data source bound AND the data markers = in the template use the=20 short da= ta marker syntax or refer to the datasource by number rather than name.= Note:=20 dataSourceName does not include a data marker's column name, f= or example, the=20 dataSourceName for=20 %%=3DProducts.ProductID is "Products."=20
property
The=20 DataBinding= Properties object which contains information about how the data should = be bound to the template.=20 property Must be specified, but the=20 DataBindingProperties need not be set beforehand. To bind data= to a template with the default=20 DataBindingProperties, pass in=20 ExcelTemplate.CreateDataBindingProperties() as the=20 property value. Otherwise, use the=20 ExcelTemplate.CreateDataBindingProperties() method to generate= a new=20 DataBindingProperties object and set the=20 Dat= aBindingProperties.MaxRows,=20 D= ataBindingProperties.Transpose, and/or=20 DataBindingProperties.WorksheetName properties for the workbook.

Exceptions

=20
ArgumentNullException
=20 BindData will throw this exception if the params source or property are null (C#) or Nothing (VB.NET).=20
SARuntimeException
=20 BindData will throw this exception if the data source contains= more rows than the worksheet can hold.
If there is more than one data marker referring to a data source and= the data source is forward only, the exception will be thrown only if the = source is larger than all bindings can hold.=20

Remarks

You can set several data sources for a singl= e template. Use the following methods to set template data sources:=20 BindCe= llData,=20 Bind= ColumnData, BindRow= Data, and=20 BindData.=20

Examples

=20
C#
=20
          ExcelTemplate xlt =3D new ExcelTemplate();
          OleDbConnection Conn =3D new OleDbConnection();
          DataTable EmployeeDt =3D null;=09=09 =20
          try
          {
               //Load data from database
               Conn.ConnectionString =3D Application["connstring"=
].ToString();

               //--- SQL Query for employee information
               string EmployeeSQL =3D "SELECT FirstName + ' ' +
                    LastName As Name, Title " +
                    "FROM Employees WHERE EmployeeID=3D?";
               OleDbCommand CmdEmployee =3D new OleDbCommand(EmployeeSQL, C=
onn);
               CmdEmployee.Parameters.Add("@EmployeeID", Employee=
Id);
               OleDbDataAdapter AdptEmployee =3D new OleDbDataAdapter(CmdEm=
ployee);
               EmployeeDt =3D new DataTable();
               AdptEmployee.Fill(EmployeeDt);
 
=09=09=09   //Sort DataView
=09=09=09   DataView dv =3D EmployeeDt.DefaultView;
=09=09=09   dv.Sort =3D "Employee DESC";
=09=09=09   
               //Bind DataView         =20
=09=09=09   xlt.BindData(dv, "Employee",xlt.CreateDataBindingProp=
erties());
=09=09  }
        
=20
vb.net
=20
          Dim xlt As New ExcelTemplate()
          Dim Conn As New OleDbConnection()
          Dim EmployeeDt As DataTable =3D Nothing
          Try
 
               'Load data from database
               Conn.ConnectionString =3D Application("connstring"=
).ToString()

               '--- SQL Query for employee information
               Dim EmployeeSQL As String =3D "SELECT FirstName & '=
 ' & _
                    LastName As Name, Title " & _
                    "FROM Employees WHERE EmployeeID=3D?"
               Dim CmdEmployee As New OleDbCommand(EmployeeSQL, Conn)
               CmdEmployee.Parameters.Add("@EmployeeID", Employee=
Id)
               Dim AdptEmployee As New OleDbDataAdapter(CmdEmployee)
               EmployeeDt =3D New DataTable()
               AdptEmployee.Fill(EmployeeDt)  
 
=09=09=09   'Sort DataView
=09=09=09   DataView dv =3D EmployeeDt.DefaultView;
=09=09=09   dv.Sort =3D "Employee DESC";
 
               'Bind DataView                 =20
          =09   xlt.BindData(EmployeeDt, "Employee", xlt.CreateDa=
taBindingProperties())
=09=09End Try
        
=20
------=_Part_8948_137677904.1711668970934--