Dear k-dub , deepakbadki
thanks you for your relpies but my pb was not resolved :(
deepakbadki said:
use generics implementation
IQUery queryOJ = session.find("select dept.name as Dname , dept.id as Did from BLL.Department as dept");
IList<string> list = queryOJ.List<String>();
now it will return you name collection and you can use that collection to bind it to datagrid.
Jojorico :
i liked the way you coded but i'm getting several errors in the conversion, the errors are:
line1: IQuery query_retrievedDept = session.Find(hql);
Code:
ERROR: Error 1 Cannot implicitly convert type 'System.Collections.IList' to 'NHibernate.IQuery'. An explicit conversion exists (are you missing a cast?) C:\Documents and Settings\bacem\Desktop\JAWAD ITECHKEY DAILY REPORTS\DataTutorials\Projects\DataTutorials -- Justin Gehtland\DataTutorials.DLL\DBHandler.cs 307 46 DataTutorials.DLL
line2: retrievedDept = query_retrievedDept.List<string>();Code:
ERROR:Error 2 The non-generic method 'NHibernate.IQuery.List()' cannot be used with type arguments C:\Documents and Settings\bacem\Desktop\JAWAD ITECHKEY DAILY REPORTS\DataTutorials\Projects\DataTutorials -- Justin Gehtland\DataTutorials.DLL\DBHandler.cs 308 53 DataTutorials.DLL
Besides, are u using IQUery class other than the NHibernate.IQuery class?
k-dub said:
So, if you have an object "ThinDepartment" with only the Name and ID properties, you could:
select new ThinDepartment(dept.Name, Dept.ID) from BLL.Department as dept
Jojo :
i've used this hql
string hql = "SELECT new DataTutorials.BLL.Department(dept.Name, Dept.ID) from DataTutorials.BLL.Department as dept";
but i'm recieving the following error :
Quote:
Incorrect query syntax [SELECT new DataTutorials.BLL.Department(dept.Name, Dept.ID) from DataTutorials.BLL.Department as dept]
Parameter name: DBHandler - ERROR IN Getting Department Properties
Actual value was NHibernate.QueryException: Incorrect query syntax [SELECT new DataTutorials.BLL.Department(dept.Name, Dept.ID) from DataTutorials.BLL.Department as dept] ---> System.ArgumentException: Item has already been added. Key in dictionary: 'dept' Key being added: 'dept'
at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
at System.Collections.Hashtable.Add(Object key, Object value)
at NHibernate.Hql.FromParser.Token(String token, QueryTranslator q)
at NHibernate.Hql.ClauseParser.Token(String token, QueryTranslator q)
at NHibernate.Hql.PreprocessingParser.End(QueryTranslator q)
at NHibernate.Hql.ParserHelper.Parse(IParser p, String text, String seperators, QueryTranslator q)
at NHibernate.Hql.QueryTranslator.Compile()
--- End of inner exception stack trace ---
at NHibernate.Hql.QueryTranslator.Compile()
at NHibernate.Hql.QueryTranslator.Compile(ISessionFactoryImplementor factory, IDictionary replacements, Boolean scalar)
at NHibernate.Impl.SessionFactoryImpl.GetQuery(String queryString, Boolean shallow)
at NHibernate.Impl.SessionImpl.GetQueries(String query, Boolean scalar)
at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters)
at NHibernate.Impl.SessionImpl.Find(String query)
at DataTutorials.DLL.DBHandler.SELECT_PROPERTIES2(String hql) in C:\Documents and Settings\bacem\Desktop\JAWAD ITECHKEY DAILY REPORTS\DataTutorials\Projects\DataTutorials -- Justin Gehtland\DataTutorials.DLL\DBHandler.cs:line 329.