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.  [ 7 posts ] 
Author Message
 Post subject: How to get data from a table to DataSet by NHirbernate??
PostPosted: Wed Aug 30, 2006 10:13 am 
Newbie

Joined: Wed Aug 30, 2006 10:06 am
Posts: 3
In my code, I want to get data from a table in MSSQL to DataSet, so then I can bind Dataset to DataGrid.
Who can help me ,plz??
Thanx.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 31, 2006 12:49 am 
Beginner
Beginner

Joined: Mon Nov 21, 2005 6:38 pm
Posts: 30
Location: New Zealand
I'm curious: why would you be using NHibernate when you want to populate a Dataset? Wouldn't it be easier to use ADO.Net?

We bind ILists of objects (returned from NH) to our grids, thus avoiding the need to go anywhere near DataSets.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 31, 2006 5:55 pm 
Newbie

Joined: Wed Aug 30, 2006 10:06 am
Posts: 3
Thank you very much for answer. So can you tell me how to bind DataGrid to IList. IList is collection of 1 dimension object.I think that the field of object will be colum, and value will be row. But I couldn't bind successfully. Can you give me one example ???
Thank again.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 01, 2006 12:00 am 
Regular
Regular

Joined: Tue Feb 21, 2006 9:50 am
Posts: 107
just assign the name of the collections to the DataSource property and the names of the properties of the class as mapping name. Here is a short sample:

Code:
public class Person
{
  private string mName;
  private string mPhone;

  public string Name
  {
    get{return mName;}
    set{mName = value;
  }

  public string Phone
  {
    get{return mPhone;}
    set{mPhone = value;}
  }
}

// Code for DataSet assuming binding an IList of Persons
IList persons = GetPersonList();
dataSet1.DataSource = persons;

// following can also be done in the designer
((DataGridTextboxColumn)dataSet1.TableStyles[0].GridColumnStyles[0]).MappingName = "Name";
((DataGridTextboxColumn)dataSet1.TableStyles[0].GridColumnStyles[1]).MappingName = "Phone";


You didn't say if you use .NET 1.1 or 2.0. In .NET 1.1, if you want to support sorting or insert new rows the concrete IList must support the IBindingList interface which you have to implement yourself.
For .NET 2.0 i'm not sure if the Framework provided collections support IBindingList.

Regards
Klaus


Top
 Profile  
 
 Post subject: Declarative binding
PostPosted: Fri Sep 01, 2006 1:34 am 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
Since you are talking about a DataGrid instead of a GridView, I assume you are using .Net 1.1. So I won't mess with two-way binding.

When you bind a DataSource control such as an DataGrid to any implementation of IEnumerable (all the collections do), the properties (not fields) are able to be bound declaratively in your DataGrid.

So in the aforementioned Person class, you can just bind to a DataGrid using Eval("Name") for one field and Eval("Phone") for another. When the call to .DataBind() occurs the control reflects on the Container.DataItem as it enumerates over each Person object and assigns the value to the TableCell (or whatever control you may have nested).

So returning an IList isn't "one-dimensional" if it is returning complex types like your business objects. It's wasteful to dump your IList into an DataSet unless you really need a DataSet (like for remote callers or something).
Hope this helps!
--MIKE


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 01, 2006 10:13 am 
Newbie

Joined: Wed Aug 30, 2006 10:06 am
Posts: 3
First, Thanks Luedi for your code. But I agree with mnichols, that's wasteful.I understand your idea(mnichols), but I'm programming in Windows-base. Is DataBind and Eval available in this scene???
Once again, can you give me your code,at hand, and the code for .Net 2.0.
Thanks for your enthusiasm.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 01, 2006 1:45 pm 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
Here is a FAQ that may help you at
http://www.windowsforms.net/Samples/Go%20To%20Market/DataGridView/DataGridView%20FAQ.doc

_________________
If this helped...please remember to rate it!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.