Simple Binding and updating

Posts   
 
    
Greg
User
Posts: 4
Joined: 18-May-2004
# Posted on: 18-May-2004 12:45:32   

Hi. I just started using llblgen and so far it seems great. I had a quick question about databinding. I have a simple form with a combo box and a datagrid. I would like to bind the customers list to the combo box and the orders list to the datagrid. Here is the code I have:

in onload of form

customers = new CustomersCollection();
customers.GetMulti( null, 0 );
cbCustomers.DataSource = customers;
cbCustomers.DisplayMember = "ContactName";
cbCustomers.ValueMember = "CustomerID";
gridOrders.DataSource = customers;
gridOrders.DataMember = "Orders";

This will create the relationship as expected. However, I cannot get the updating to work at all. How could I have databinding update an order? Could someone please post an example of how to get the updating to work. Thanks. I have tried many things, including

customers.SaveMulti( true );

etc. If it helps, I have also tried this with both the Ultragrid and the normal Windows datagrid but I cannot get it to work. Thanks for any help.

Greg

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 18-May-2004 12:55:40   

The grid appears as readonly? Or do you change something but it doesn't appear changed?

Frans Bouma | Lead developer LLBLGen Pro
Greg
User
Posts: 4
Joined: 18-May-2004
# Posted on: 18-May-2004 23:37:27   

Otis wrote:

The grid appears as readonly? Or do you change something but it doesn't appear changed?

The grid does not appear read only. I can add new records, update current records etc. However, when I click the update button that I made (the update button currently calls customer.SaveMulti(true)), nothing seems to save to the database. If I close the program and reopen it, none of the modified data was saved to the database. I do see the following sql commands being run:

SET TRANSACTION ISOLATION LEVEL READ COMMITTED;BEGIN TRANSACTION [SaveMulti]COMMIT TRANSACTION

but it does not save anything. What I would like to happen is the following:

  1. select a customer in the combo box and the appropriate orders in the grid show up (this works fine)

  2. Modify an order (say by changing the frieght cost ) in the grid

  3. Have the database updated with the changes to the database when the update button is pressed.

Right now the grid is modified but the changes are not reflected in the tables.

I am not sure if this helps any but I looked at the order right before I called SaveMulti using this code:

customers[3].Orders[0].Freight

customers[3].Orders[0].IsDirty

The result was that the freight shows the modified order and the row is marked as dirty - both as I expected. However, calling SaveMulti does not update the order to the database.

I noticed that calling

customers[3].Orders.SaveMulti( true );

causes the row to correctly update in the database. However, this is not what I need because I do not want to have to scan through the customer and order rows to find what orders for each customer have been updated.

Thanks for any help.

Greg

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 19-May-2004 10:26:22   

This is a bug I think.

Code of SaveMulti(bool)


/// <summary>
/// Saves all new/dirty Entities in the IEntityCollection in the persistent storage. If this IEntityCollection is added
/// to a transaction, the save processes will be done in that transaction, if the entity isn't already added to another transaction.
/// If the entity is already in another transaction, it will use that transaction. If no transaction is present, the saves are done in a
/// new Transaction (which is created in an inherited method.)
/// </summary>
/// <param name="recurse">If true, will recursively save the entities inside the collection</param>
/// <returns>Amount of entities inserted</returns>
/// <remarks>All exceptions will be bubbled upwards so transaction code can anticipate on exceptions.</remarks>
public virtual int SaveMulti(bool recurse)
{
    int amountSaved = 0;

    for(int i=0;i<List.Count;i++)
    {
        IEntity entityToSave = (IEntity)List[i];
        bool saveEntity = (entityToSave.IsNew || entityToSave.Fields.IsDirty);

        if(recurse && saveEntity)
        {
            saveEntity = !_containingTransaction.EntitiesInTransaction.Contains(entityToSave.ObjectID);
        }
        
        if(saveEntity)
        {
            if(!((ITransactionalElement)List[i]).ParticipatesInTransaction)
            {
                // doesn't participate in a transaction, add it to the current transaction. Has to be available.
                _containingTransaction.Add((ITransactionalElement)List[i]);
            }
            bool wasSuccesful = entityToSave.Save(recurse);
            if(wasSuccesful)
            {
                amountSaved++;
            }
        }
    }
    return amountSaved;
}

This of course will not walk all objects in the collection during a recursive save, only the dirty objects. I fixed this bug in adapter some time ago, but didn't test selfservicing if it had the same error. Normally you won't run into this bug a lot as it is not that efficient to simply save a complete collection with maybe hundreds of objects which have to be traversed, but it can be conveniant to do so.

I'll try to upload a hotfix for this a.s.a.p.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 19-May-2004 10:55:32   

I've uploaded a hotfix for this problem. Please check out the runtime libraries section in the customer area.

Frans Bouma | Lead developer LLBLGen Pro
Greg
User
Posts: 4
Joined: 18-May-2004
# Posted on: 19-May-2004 11:42:03   

Hi. Thanks very much for your help. I will check out the fix today. I appreciate the quick response to my question!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 19-May-2004 12:21:19   

Greg wrote:

Hi. Thanks very much for your help. I will check out the fix today. I appreciate the quick response to my question!

No problem simple_smile Bugs have to be squashed a.s.a.p. simple_smile Nothing is more irritating than having to work with a 3rd party lib / tool which contains a bug and nothing is done to get it fixed. (Hi Microsoft! wink )

Frans Bouma | Lead developer LLBLGen Pro
Greg
User
Posts: 4
Joined: 18-May-2004
# Posted on: 22-May-2004 09:55:12   

Hi. I had quite a time getting this to work. Here is the story simple_smile

The day you released the hotfix, I downloaded it and started to work with it. I copied the dlls to the runtime directory, reset the references in my app, etc. and tried the hotfix. However, the original problem was still there. For a while I thought there was still something wrong with my code. Eventually, I decided that the solution still seemed to be pointing to old versions of the dll, even though I had replaced those versions with the new versions. To test this, I created a new project and did a simple test - everything worked great. After this, I went back to my original project, switched to release mode, and it worked in release mode! Just switching back to debug mode without any other changes caused the original problem to reappear. Obviously somehow it is still keeping the old version of those dlls somewhere. Finally I deleted the solution suo file and moved the program to another directory. One of these two actions fixed the problem and it works great now. Whew! Thanks again for you help with this. Hopefully this little story will help anyone else who has this strange problem. I am still not sure where it was keeping those old versions of the dlls.

Greg

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 22-May-2004 09:59:23   

Thanks Greg!

Some other users had problems before but we never could find a solution. Thanks for pointing this out, simply removing a suo file is an easy fix simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Developer
User
Posts: 58
Joined: 05-May-2004
# Posted on: 22-May-2004 14:08:14   

C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files

Delete all ASP.NET Temporary Files may help to resolve this issue as well.

Regards, Developer