OleDbDataReader CategoryRdr = GetCategoryReader();
try
{
ExcelTemplate xlt = new ExcelTemplate();
xlt.BindData(CategoryRdr,
"Category",
ExcelTemplate.CreateDataImportProperties());
} catch(System.Exception ex) {
} finally {
//--- The OleDbDataReader must be open when it's passed
//--- to ExcelTemplate. Remember to close it after use.
if(CategoryRdr!=null)
CategoryRdr.Close();
}
//--- Get an OleDbDataReader containing a list of product categories
private OleDbDataReader GetCategoryReader()
{
OleDbConnection Conn = new OleDbConnection();
Conn.ConnectionString = Application["connstring"].ToString();
//--- SQL query for a list of categories
string CategorySQL = "SELECT CategoryName FROM Categories";
OleDbCommand Cmd = new OleDbCommand(CategorySQL, Conn);
Conn.Open();
return Cmd.ExecuteReader();
}
|