Joined: Mon Feb 06, 2006 1:40 am Posts: 1 Location: Trivandram,Kerala
|
You can create crystal reports using nHibernate. follow the steps
1. Create a dataset (.xsd) file and create an element with a name.
2. Design the report using the data set. ( follow PUSH method of crystal reports)
3. Now you get the data using HQL or Directly from nhibernate object and pass those data to dataset. IT will be displayed in the report. Since the datset you had created is not linked with database directly we can say its a database Independent report.
Eg.
I had created a dataset and an element in the dataset named rptstock. and in my code behind i had created a method for creating a dataset. see the code
public DataSet GetDataSource(string HSql)
{
DataSet objDataSet=new DataSet();
DataTable objTable=new DataTable("rptStock");
IList objlist=GetReportData(HSql);
objTable.Columns.Add("cName");
objTable.Columns.Add("cDescription");
objTable.Columns.Add("nQty");
objTable.Columns.Add("dDate");
objTable.Columns.Add("cType");
DataRow myRow;
foreach (object[] arrobject in objlist)
{
int i=0;
myRow=objTable.NewRow();
myRow[0]=arrobject [0]
myRow[1]=arrobject [1]
myRow[2]=arrobject [2]
myRow[3]=arrobject [3]
myRow[4]=arrobject [4]
objTable.Rows.Add(myRow);
}
objDataSet.Tables.Add(objTable);
return objDataSet;
}
--Getting Data from nHibernate objects
private IList GetReportData(string sSQL)
{
cfg=new Configuration();
cfg.AddAssembly("AssemblyName");
factory = cfg.BuildSessionFactory();
ISession session=factory.OpenSession();
string strHBQ=sSQL;
IList objList= session.CreateQuery(strHBQ).List();
session.Close();
return objList;
}
Now u can set datasource of the report and view report
|
|