Binding data in my DatagridView in C# using Nhibernate -
i want add data datagridview. dniveau , dcycle are:
class dniveau : idniveau { dparams dparams; itransaction tx; isession mysession; public niveau oncreate(niveau niveau) { niveau nivo = null; dparams = new dparams(); mysession = dparams.isession(); tx = mysession.begintransaction(); mysession.save(niveau); nivo = mysession.get<niveau>(niveau._idniveau); tx.commit(); mysession.close(); return null; } public list<niveau> getall() { list<niveau> lniveau; dparams = new dparams(); mysession = dparams.isession(); tx = mysession.begintransaction(); tx.commit(); lniveau = (list<niveau>)mysession.createcriteria<niveau>().list<niveau>(); mysession.close(); return lniveau; } }
dcycle.cs
class dcycle : idcycle { protected static readonly ilog _log = logmanager.getlogger(typeof(program)); dparams dparams; itransaction tx; isession mysession; public cycle oncreat(cycle cycle) { dparams = new dparams(); mysession = dparams.isession(); tx = mysession.begintransaction(); mysession.save(cycle); tx.commit(); mysession.close(); return null; } public list<cycle> getall() { list<cycle> lclis; dparams = new dparams(); mysession = dparams.isession(); tx = mysession.begintransaction(); lclis = (list<cycle>)mysession.createcriteria<cycle>().list<cycle>(); tx.commit(); // mysession.close(); return lclis; } }
this objects niveau , cycle
public class niveau { public virtual int _idniveau { get; set; } public virtual string _designation { get; set; } public virtual cycle _cycle { get; set; } public override string tostring() { return string.format("_idniveau: {0}, _designation: {1}, _cycle: {2}"); } } public class cycle { public virtual int _idcycle { get; set; } public virtual string _designation { get; set; } public virtual etablissement etablissement { get; set; } }
and hibernate mapping file both
<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="openskull.entites" assembly="openskull"> <class name="cycle" table="cycle"> <id name="_idcycle" column="idcycle"> <generator class="native"/> </id> <property name="_designation" column="designation"/> <many-to-one name="etablissement" class="etablissement" column="idetablissement" cascade="save-update"/> </class> </hibernate-mapping> <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="openskull.entites" assembly="openskull"> <class name="niveau" table="niveau"> <id name="_idniveau" column="idniveau"> <generator class="native"/> </id> <property name="_designation" column="designation"/> <many-to-one name="_cycle" class="cycle" column="idcycle" cascade="save- update"/> </class> </hibernate-mapping>
and code use add data
if (lnivo != null && icycl != null) { cursor.current = cursors.waitcursor; // datagridview.datasource = lnivo; niveaubindingsource4.datasource = lnivo; cyclebindingsource3.datasource = icycl.getall(); cursor.current = cursors.default;
when compile ok when click form appears error appears:
the following exception occurred in datagridview: system.formatexception: datagridviewcomboboxcell value not valid.
to replace default dialog please handle dataerror event.
and after error:
thanks blocked. new language
Comments
Post a Comment