TextBox bound to autonumber column doesn't update on Insert

Posts   
 
    
Waveslam
User
Posts: 18
Joined: 20-Nov-2006
# Posted on: 01-Dec-2006 00:36:12   

Hi I have an Entity object generated against a table where the PK is an autonumber column in SQL Server. This means that when I create a new empty row in my C# code (by instantiating a new Entity object), this column/property is set to 0. Then when I call .Save() on the object, the Enitity property updates to whatever value it was assigned eg. 834 or whatever the next number happens to be.

I have this PK column bound to a textbox, which initially appears as 0, as it should. However, the problem is that the texbox doesn't update after the .Save() call to show the newly assigned number. My code is:

            this.txtBuID.DataBindings.Add(new Binding("Text", ibBugRow, "buID"));

Where txtBuID is my textbox object, and ibBugRow.buID is the PK column.

When I .Save() a new instance of an ibBug object, the textbox remains at 0, even though I can see the buID PK column change to its new value in the debugger. I have even tried reloading the ibBug object from the DB after the save with:

            UnitOfWork uow = new UnitOfWork();
            uow.AddForSave(ibBugRow, true);
            uow.Commit(new Transaction(IsolationLevel.ReadCommitted, "UOW"), true);
            ibBugRow.Refetch();

But it makes no difference. (Note that I am using the UoW object to resolve another concurrency issue). ANyway, where am I going wrong? WHy doesn't the textbox update with the newly assigned PK value?

I am using SQL Server 2000, C#, .NET 2.0, Winforms, LLBLGenPro 2.0.0.0, SelfServicing.

Thanks heaps Cheers Brett

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 01-Dec-2006 09:30:50   

I think you have to clear the DataBindings and re-bind again after the entity is saved/loaded from the database.

As when the entity is saved/loaded with new values, there is no NotifyPropertyChanged event raised, as the property was not changed in the code but was fetched from the database. (i.e. an entity fetched from the database is considered as fresh).