473,396 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

NHIbernate -.NET-Binding IList to GridView in .Net 2.0

Hi,

Is it possible to get the results of HQL queries in DataSet?.I want to display results of HQL query to GridView. As HQL results are returned in the form of IList/List collections i am unable to Bind to Grid View.

pls let me know,

1. How to bind IList collections to Grid view?
eg:
IList results=Query.List()
GridView1.DataSource=results;
GridView.DataBind();

if i run the above code it will display the result in Grid only if i have the result returned as only 1 row.If more than one row is returned as a result of executing HQL query, it returns the properties of IList in the GridView..
any solution for this problem??
(or)

2 . Is it possible to return the result of HQL query directly in the Form of DataSet?

thanks in Advance,
Feb 13 '08 #1
5 12438
kenobewan
4,871 Expert 4TB
Here is an article that may help:
Hibernate Query Language (HQL)
Feb 13 '08 #2
Here is an article that may help:
Hibernate Query Language (HQL)

Thanks for the reply.
but my question is: HQL returns an Ilist..that is fine.But how do I bind the IList to Gridview?
Is there any method of GridView DataBinding with IList? or
Is there any other method of executing HQL queries other than List and IList so that i can directly get the results in the form of DataSet/DataTable?

Thanks,
Feb 13 '08 #3
kenobewan
4,871 Expert 4TB
That would normally be the datasource of the gridview. HTH.
Feb 14 '08 #4
Ciao,

This is the code that I always use in order to bind a IList returned by Nhiberbate to a DataGridView:

Expand|Select|Wrap|Line Numbers
  1.  private BindingSource bs = new BindingSource();
  2.         gridView.DataSource = bs;
  3. ......................................................................................................
  4.         IList<MyType> myList= criteria.List<MyType>();
  5.         bs.DataSource=myList;
  6.         bs.ResetBindings(false);
You first create a BindingSource object that you link to the DataSource of your grid. After that, when you have retreived you IList (here I use ICriteria but is the same if you use HQL to retreive the IList) you link the DataSource of the BindingSource to the IList and everytime you change the data in the IList the only thing you need to call is bs.ResetBindings(false)

Hope it helps!
Sep 12 '08 #5
Expand|Select|Wrap|Line Numbers
  1. ISQLQuery newQuery = session.CreateSQLQuery("select * from Test_Persons comp,Test_ProductOrder ORD WHERE comp.custId= ORD.CustomerID");
  2.             IList list1 = (IList)newQuery.List();
  3.             DataTable tab = new DataTable();
  4.             for (int i = 0; i < columncount; i++)
  5.                 tab.Columns.Add();
  6.             for (int i = 0; i < list1.Count; i++)
  7.             {
  8.                 Object[] newobj = (Object[])list1[i];
  9.                 tab.Rows.Add(newobj);
  10.             }
  11.             GridView1.DataSource = tab;
  12.             GridView1.DataBind();
  13.  
-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0

Hope the code helps
May 22 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Roman | last post by:
Hello i got this simple problem using nhibernate. I want to chang the id( primary key of the) object and update it, to change this key. i me getting nhibernate exception like this: identifier...
0
by: Aquila Deus | last post by:
The documents on their website are completely wrong. Following is the a real example that works with NHibernate 1.0.2.0: <?xml version="1.0" encoding="utf-8"?> <configuration...
1
by: erin.sebastian | last post by:
Hello All, I am new to hibernate and new to nHibernate. I created a small app and when i try and run it i get the error i posted at the bottom of this message. I am using the helper class that...
5
by: igotyourdotnet | last post by:
I took over an asp.net C# app from a former developer that left. Ever so ofter I get an error message: Access is denied: 'NHibernate'. Description: An unhandled exception occurred during the...
0
by: TigrouMeow | last post by:
Hello, I'm trying to make a "clean" webservice, using Nhibernate. I'm facing some issues, but i'm quite the beginner with that kind of system. When there are more than 2 clients connected on my...
0
by: beantaxi | last post by:
Hello all, I'm trying to write a simple program, using VS C# 2005 Express and SQL Server Express with NHib 1.0.2. No matter what I try, I'm unable to connect: cannot open connection at...
4
by: IceMan | last post by:
Hi, I am using the configuration object and passing it a Assembly object to load. The assembly object i pass in is from a dll which is in a different folder then the Nhibernate dll. The...
1
by: Alexander Vasilevsky | last post by:
Does the number NHibernate download data? For example, first can be downloaded 100 rows of data, and then as necessary podgruzhat else. Where can I read about NHibernate and its potential? ...
14
by: thj | last post by:
Hi, I was wondering what you guys are using and why? LINQ to SQL or NHibernate? Thanks in advance, Tommy
1
by: moorcroft | last post by:
Hi I'm looking for help with getting the latest NHibernate to work with my .Net 3.5 VS 2008 project that I am migrating from .Net 2.0 on VS 2005. Previously (VS 2005 .Net 2.0) I would use the folling...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.