thav,
is there a particular reason why you are writing your own sql and not using HQL or createCriteria? it really is a lot simpler:
Code:
<class name="student">
<property name="firstName" />
...
<bag name="belts">
<one-to-many class="belt" />
</bag>
</class>
<class name="belt">
<property name="rankValue" />
...
<one-to-one name="description" class="beltDescription" />
</class>
then, in your DAO (or however you are designing your Data Access Layer):
Code:
public IList getAllStudents(params string[] sortFields) {
ICriteria crit = session.CreateCriteria(typeof(Student));
if (sortFields != null) {
foreach (string sortField in sortFields) {
c.AddOrder(Order.Asc(sortField));
}
}
return c.List();
}
then somewhere in your presentation layer (codebehind file):
Code:
DataGrid myStudentDG;
myStudentDG.DataSource = myDAO.GetAllStudents();
myStudentDG.DataBind();
and in your aspx file you can bind specific fields using the
Code:
<%# DataBinder.Eval(Container.DataItem, "FieldName") %>
notation. So something like:
Code:
<asp:datagrid id="AnswerSet" AutoGenerateColumns="False" Runat="server">
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>FirstName</HeaderTemplate>
<ItemTemplate><%# DataBinder.Eval(Container.DataItem, "FirstName") %></ItemTemplate>
<EditItemTemplate><asp:TextBox ID="FirstName" CssClass="textfield" Enabled=False Text='<%# DataBinder.Eval(Container.DataItem, "FirstName") %>' Runat=server /></EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderTemplate>Belt Rank</strong></HeaderTemplate>
<ItemTemplate><%# DataBinder.Eval(Container.DataItem, "Belt.RankValue") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType=LinkButton EditText="Edit" CancelText="Cancel" UpdateText="Update" />
</Columns>
</asp:datagrid>
obviously there is much more you can do with the datagrid, but by having your DAO return a list of student objects, you can simply walk the object graph to populate the DG. much easier that trying to get NH to return "resultsets" or whatever it is that Microsoft expects.
-devon