NHibernate's data paging technology (continued)

xiaoxiao2021-03-06  83

NHibernate's data paging technology (continued)

I have introduced how to implement data add, modify, and delete in NHibernate. If you have interested friends, please refer to http://www.cnblogs.com/surprise/archive/2004/10/13/51701.aspx. It is here to talk about the previous content.

1. Interface Add

Type object name text attribute value Button Button1 Show DataGrid DataGrid1

2. Code implementation

Double-click the "display" button

Private void Button1_Click (Object Sender, System.Eventargs E)

{

NHDATABIND ();

}

Private void nhDatabase () // data binding code

{

McFG = New Configuration ();

McFg.addxmlfile (System.Web.httpContext.current.server.mappath ("UserHbm.xml");

ISESSION vSession = mcfg.buildsessionFactory (). OpenSession ();

ITransaction vTransaction = vsession.begintransaction ();

Try

{

IList Vlist = vsession.find ("from WebnHibernate.EntityClass); // HQL statement implements data query

DataGrid1.datasource = VLIST;

DataGrid1.databind ();

vTransaction.commit ();

LabMessage.Text = "OK";

}

Catch (Exception EX)

{

vTransaction.rollback ();

LabMessage.Text = "Error";

}

Finally

{

vSession.close ();

}

}

Create a DataGIRD event handling

Private void DataGrid1_pageIndexchanged (Object Source, System.Web.ui.WebControls.DataGridPageChangeDeventargs E)

{

DataGrid1.currentPageIndex = E.NewpageIndex;

NHDATABIND ();

} Finally completed the entire small stuff, I would like to share with everyone.

转载请注明原文地址:https://www.9cbs.com/read-106402.html

New Post(0)