//--- Get a DataReader
//--- WordWriter accepts OleDbDataReader, SqlDataReader, and AdomdDataReader
OleDbDataReader dr = GetOleDbDataReader();
WordTempalte oWW = new WordTemplate();
oWW.Open(Page.MapPath("./template.doc"));
//--- Set a data source for the repeat block
//--- defined by the bookmark "Page"
//--- "dr" is the DataReader containing information to be
//--- imported and repeated in the repeat block
//--- Set MaxRows to 10. Only 10 rows from the DataReader
//--- will be imported
oWW.SetRepeatBlock(dr, "Page", 10);
oWW.Process();
oWW.Save(Page.Response, "EmployeeOutput.doc", false);
//--- Close the DataReader in a finally block
dr.Close();
private OleDbDataReader GetOleDbDataReader()
{
OleDbConnection Conn = new OleDbConnection(connString);
//--- SQL Query for categories.
string CategorySQL = "SELECT CategoryID, CategoryName," +
"Description FROM Categories";
Conn.Open();
return new OleDbCommand(CategorySQL, Conn).ExecuteReader(
CommandBehavior.CloseConnection);
}
|