Mcfg=new Configuration ()///Create configuration Class
Mcfg.addxmlfile (System.Web.HttpContext.Current.Server.MapPath ("Userhbm.xml"))//Indicates the mapping file Userhbm.xml
Entityclass ventity=new Entityclass ();
Ventity.id=txtid.text;
Ventity.username=txtname.text;
Ventity.password=txtpassword.text;
Ventity.emailaddress=txtemail.text;
ISession vsession= mcfg.buildsessionfactory (). Opensession ();//Create a session factory, in general you should use a single instance object to encapsulate the session factory.
ITransaction vtransaction = Vsession.begintransaction ();//create things to handle
Try
{
Vsession.save (ventity);//Add data to the database
Vsession.update (ventity); Modifying data to a database
Vtransaction.commit ();
Labmessage.text= "OK";
}
catch (Exception ex)
{
Vtransaction.rollback ();
labmessage.text= "Error";
}
Finally
{
Vsession.close ();
}
}
Because I also just contact NHibernate soon, there are a lot of technical difficulties do not understand, but also need more efforts, is willing to discuss with you.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.