These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: IList x DataSet
PostPosted: Tue Nov 20, 2007 11:45 am 
Newbie

Joined: Wed Nov 14, 2007 9:44 am
Posts: 4
How to put the outcome of this consultation within a dataset???

NHibernateHelper.GetCurrentSession().CreateQuery("From Usuario").List<Equipe>()

_________________
get{ return heliegesio;}


Top
 Profile  
 
 Post subject: Converting Objects in Ilist to a Dataset in Nhibernate
PostPosted: Wed Jun 04, 2008 7:44 am 
Newbie

Joined: Wed Jun 04, 2008 6:42 am
Posts: 2
Location: pune, india
Nhibernate by default doesnot provide an interface for fetching data into a dataset. So you have to write custom code to create a dataset based on the objects stored in the IList Collection.
I too was facing the same problem until i found the solution in this article

http://forum.hibernate.org/viewtopic.ph ... ht=dataset
This guy has beautifully explained it.

I used a similar kind of code here:

//Method for returning a dataset using Nhibernate
public DataSet GetDataSource()
{
DataSet objDataSet=new DataSet();
DataTable objTable=new DataTable("CurrencyTable");
IList objlist=GetCurrencyList();
objTable.Columns.Add("CurrencyId");
objTable.Columns.Add("CurrencyName");
objTable.Columns.Add("CountryName");


DataRow myRow;
foreach (object[] arrobject in objlist)
{

myRow=objTable.NewRow();
myRow[0]=arrobject [0];
myRow[1]=arrobject [1];
myRow[2]=arrobject [2];

objTable.Rows.Add(myRow);
}
objDataSet.Tables.Add(objTable);
return objDataSet;
}

//Method for executing the query in nhibernate.I have used the NhibernateHelper class provided by nhibernate for beginning the session and closing the session
private IList GetCurrencyList()
{
ISession session=NHibernateHelper.GetCurrentSession();
IQuery query = session.CreateSQLQuery("SELECT Currency.CurrencyId, Currency.CurrencyName, country.CountryName FROM country INNER JOIN Currency ON country.CountryId = Currency.CountryId");
IList objList = query.List();
NHibernateHelper.CloseSession();
return objList;
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.