Delete not persisted

Posts   
 
    
scotru
User
Posts: 104
Joined: 16-Feb-2006
# Posted on: 23-Jun-2006 08:14:37   

I'm having trouble persisting a deleted entity (that is removing it from the database). I'm pretty new to LLBLGenPro and also to vs2005 (having recently upgraded from 2003). I've been browsing through the forums and I'm sure the answer is right under my nose--but I can't seem to find it.

I have bound a DataGrid to a collection of related items (first setting AllowRemove true):


            student.Requests.AllowRemove = true;
            requestsCollectionBindingSource.DataSource = student.Requests;

Next I added code to handle my deletion. I've played with several things here and have tried to get a fresh new entity:


        private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
        {
            RequestsEntity item = (RequestsEntity)(requestsCollectionBindingSource.Current);
            if (item != null)
            {
                RequestsEntity entity = new RequestsEntity(item.RequestId);
                item.Delete();
            }
        }

after having first tried just deleting from my bindingsource item


            RequestsEntity item = (RequestsEntity)(requestsCollectionBindingSource.Current);
            if (item != null)
            {
                   item.Delete();
            }

The item is removed from my DataGrid, but not from the database and returns next time I visit. confused

Can anyone help? Thanks in advance! By the way, I'm using 2-class self-servicing code.

Thanks!

scotru
User
Posts: 104
Joined: 16-Feb-2006
# Posted on: 23-Jun-2006 08:53:02   

Ah--figured it out! My problem was I didn't realize that the DeleteItem property of the BindingNavigator was deleting my row from the data source (collection) before my click event handler could get at it--thus the "current" row was no longer the one I wanted to delete. I cleared the "DeleteItem" property of the BindingNavigator in the designer and handled removing the item from the datasource with a call to RemoveCurrent.


        private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
        {
            RequestsEntity item = (RequestsEntity)(requestsCollectionBindingSource.Current);
            if (item != null)
            {
                RequestsEntity entity = new RequestsEntity(item.RequestId);
                requestsCollectionBindingSource.RemoveCurrent();
                requestsCollectionBindingSource.EndEdit();
                item.Delete();
            }
        }

Thanks to anyone who took a look at this.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 23-Jun-2006 08:57:09   

Would you please check to see if a SQL query is generated or not? and if a sql query is generated, try to ruyn it against the database to see if it succeeds or fails.

To know how to get the generated query, please refer to LLBLGen Pro manual "Using the generated code -> Troubleshooting and debugging"