Monday, 15 April 2013

c# - Object Disposed exception when scrolling datagrid view left to right -



c# - Object Disposed exception when scrolling datagrid view left to right -

i using linq sql classes managing info , using next code bind info datagridview in windows forms. exception thrown when trying scroll datagrdview left right.

the 2 tables involved here :

billing_userrole

roleid pk

rolename

createdts

updatedts

billing_user

userid pk //this referenced in other tables well.

roleid fk

username

password

firstname

lastname

createdts

updatedts

the create tables queries following

create table [dbo].[billing_userrole]( bk_userroleid bigint identity(100,1) not null, bk_userrolename nvarchar(128) not null, bk_createdts datetime null, bk_updatedts datetime null, constraint [pk_billinguserrole] primary key clustered ( [bk_userroleid] asc )with (pad_index = off, statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary] ) on [primary] /* table name : billing_user */ create table [dbo].[billing_user]( bk_userid bigint identity(1,1) not null, bk_username nvarchar(256) not null, bk_password nvarchar(2048) not null default('none'), bk_firstname nvarchar(256) not null, bk_lastname nvarchar(256) not null, bk_mobileno nvarchar(128) not null, bk_address nvarchar(2048) null default('none'), bk_remarks nvarchar(2048) null default('none'), bk_userroleid bigint not null, bk_createdts datetime null, bk_updatedts datetime null, constraint [pk_billinguser] primary key clustered ( [bk_userid] asc )with (pad_index = off, statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary], constraint [fk_billinguser_billinguserrole] foreign key(bk_userroleid) references [dbo].[billing_userrole](bk_userroleid) )

code in form bind datagridview on form_load

private void usermanagementform_load(object sender, eventargs e) { seek { using (billingkioskdatalayerdatacontext dc = new billingkioskdatalayerdatacontext()) { table<billing_user> usertable = dc.gettable<billing_user>(); var userlist = usertable.select(o=>o).tolist(); billing_userbindingsource.datasource = userlist; datagridview1.datasource = billing_userbindingsource; } } grab (exception ex) { debug.writeline(ex.message); } }

here's code exception thrown. it's auto generated code. why happen ? i exception when scroll datagridview left right view remaining fields.

[global::system.data.linq.mapping.associationattribute(name="billing_userrole_billing_user", storage="_billing_userrole", thiskey="bk_userroleid", otherkey="bk_userroleid", isforeignkey=true)] public billing_userrole billing_userrole { { homecoming this._billing_userrole.entity; **// disposedobjectexception :cannot access disposed object here** } set { billing_userrole previousvalue = this._billing_userrole.entity; if (((previousvalue != value) || (this._billing_userrole.hasloadedorassignedvalue == false))) { this.sendpropertychanging(); if ((previousvalue != null)) { this._billing_userrole.entity = null; previousvalue.billing_users.remove(this); } this._billing_userrole.entity = value; if ((value != null)) { value.billing_users.add(this); this._bk_userroleid = value.bk_userroleid; } else { this._bk_userroleid = default(long); } this.sendpropertychanged("billing_userrole"); } } }

stack trace :

@ system.data.linq.datacontext.gettable(type type) @ system.data.linq.commondataservices.getdatamemberquery(metadatamember member, expression[] keyvalues) @ system.data.linq.commondataservices.deferredsourcefactory`1.executekeyquery(object[] keyvalues) @ system.data.linq.commondataservices.deferredsourcefactory`1.execute(object instance) @ system.data.linq.commondataservices.deferredsourcefactory`1.deferredsource.getenumerator() @ system.linq.enumerable.singleordefault[tsource](ienumerable`1 source) @ system.data.linq.entityref`1.get_entity() @ billingkiosk.billing_user.get_billing_userrole() in e:\xghprojects\billingkiosk\billingkiosk\billingkioskdatalayer.designer.cs:line 663

most experiencing lazy or deferred loading of columns in related entity. can utilize dataloadoptions.loadwith method include related columns.

http://msdn.microsoft.com/en-us/library/system.data.linq.dataloadoptions.loadwith(v=vs.110).aspx

by way: easy found if realy case: remove using() on datacontext. [only diagnostics...]. if works well, lazy loading...

c# winforms linq-to-sql datagridview windows-applications

No comments:

Post a Comment