Entity.Save() Problem VS 2005 NET 2.0

Posts   
 
    
Andreas
User
Posts: 4
Joined: 22-Jan-2007
# Posted on: 23-Jan-2007 00:06:09   

SQL Server 2005 SP1 SD.LLBLGen.Pro.DQE.SqlServer.NET20 v2.0.50727 Self Servicing Two Classes 2005

I have a form which i bound an Entity to textboxes


adrId.DataBindings.Add("Text",_selectedAdresse,"AdrId");
firma.DataBindings.Add("Text",_selectedAdresse,"Firma");
anrede.DataBindings.Add("Text",_selectedAdresse,"Anrede");
vorname.DataBindings.Add("Text",_selectedAdresse,"Vorname");
name.DataBindings.Add("Text",_selectedAdresse,"Name");
adresse.DataBindings.Add("Text",_selectedAdresse,"Adresse");
plz.DataBindings.Add("Text",_selectedAdresse,"Plz");
ort.DataBindings.Add("Text",_selectedAdresse,"Ort");
land.DataBindings.Add("Text",_selectedAdresse,"Land");

The data where load an I can see it on the form and all is ok. But when i change something in the field "Vorname" and then save _selectedAdresse. All is ok, but the dates in the SQL Server 2005 are not changed.

bool succeeded = _selectedAdresse.Save();

succed is always true.

If I click first to the field "AdrId" and then change something in "Vorname" and then click to Name and after I save the _selectedAdresse. Now it works and the dates in the Sql Server are chenged.

Thanks for all help

Andreas

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 23-Jan-2007 02:29:15   

What do you mean the dates are changed? Is vorname a date or name? Sorry I'm just confused.

Andreas
User
Posts: 4
Joined: 22-Jan-2007
# Posted on: 23-Jan-2007 07:27:17   

Both are dates, I give an example

Vorname = Peter Name = Meier

And now I change the value Vorname = Kurt. When I only change this field in the form, after save in the database is Vorname = Peter.
Does I click first on the Fields AdrId and Name then is after save in the database Vorname = Kurt Hope this can explain the problem.

Andreas

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 23-Jan-2007 08:04:44   

You are not using a BindingSource, are you?

You may debug and check the field value just before the save. I guess the problem is a databinding problem, the field value doesn't get refreshed from the textbox unless you lose the focus to another control.

Andreas
User
Posts: 4
Joined: 22-Jan-2007
# Posted on: 23-Jan-2007 08:48:37   

Walaa wrote:

You are not using a BindingSource, are you?

You may debug and check the field value just before the save. I guess the problem is a databinding problem, the field value doesn't get refreshed from the textbox unless you lose the focus to another control.

How can I made a Binding Source for an Entity? I think it's only for a collection possible. So I made BindingSource for the collection. The Northwind Example is for the 1.02005 Template and not for the 2.0. Can you send me an example for the 2.0?

Thanks a lot

Andreas

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 23-Jan-2007 09:20:36   

Check this specific post by Frans: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7526#41558

Also check this thread about databinding pf Nullable dataTypes Fields: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8064

I sometimes use a bndingSource with an entityCollection (having 1 entity inside) And check the following thread too for the "bindingSource.EndEdit();" trick: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8381

Andreas
User
Posts: 4
Joined: 22-Jan-2007
# Posted on: 25-Jan-2007 15:30:26   

Walaa wrote:

Check this specific post by Frans: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7526#41558

Also check this thread about databinding pf Nullable dataTypes Fields: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8064

I sometimes use a bndingSource with an entityCollection (having 1 entity inside) And check the following thread too for the "bindingSource.EndEdit();" trick: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8381

I read all this, but the problem couldn't solve from me. Then I set the values direct via code

                
_selectedAdresse.MandantId = Convert.ToInt32(IBWConfigAllgemein.mandant);
_selectedAdresse.AdrId = this.adrId.Text;
_selectedAdresse.Firma = this.firma.Text;
_selectedAdresse.Anrede = this.anrede.Text;
_selectedAdresse.Vorname = this.vorname.Text;
_selectedAdresse.Name = this.name.Text;
_selectedAdresse.Save();

The problem is the same. The dates will be saved only when I clicked an other field after changing a value. I can't understand this. Is there a other way to save an Entity. Before I change to NET 2.0 the code works and the dates where saved. Thanks for help Andreas

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 25-Jan-2007 16:29:44   

This is a .NET issue, they hardcoded special code for 'datatable'. See: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=8381

Also, you run into this when the CurrencyManager on the forum thinks it should invoke complex databinding. Complex databinding occurs when you have one or more IList targeting bindings on the form (grid, listview etc. ). This then means that BeginEdit/EndEdit is called, so the entity can't do anything else but postpone the changed event which happens when the focus is moved away to another row, as EndEdit is then called. I can't solve this otherwise, databinding works that way.

In .NET 1.x, it was a little different, because events were raised differently (not a central event, but every property had its own event).

I know it can be frustrating, tell me about it disappointed , though there's little I can do here, I'm afraid.

Frans Bouma | Lead developer LLBLGen Pro