PC Review


Reply
Thread Tools Rate Thread

Propogate from Listbox back to database with DeleteCommand

 
 
Ori
Guest
Posts: n/a
 
      20th May 2004
Hi,

I have a listbox which is bounded to a datatable. I allow the users to
add/remove items from the list while adding/remove rows from the
datatable which function as the datasource.

When I come to do the "update" back to the datatbase using the
SqlDataAdapter and the insert/delete command, I see that only the new
rows are added and the old one doesn't. removed from the database.

After a short investigation, I notice that if I remove the rows
directly from the datatable the deletecommand doesn't have a row to
operate on.

Can someone explain me exactly how to use the delete command along
with a binding to a listbox which you can remove and add items.

Thanks,

Ori.
 
Reply With Quote
 
 
 
 
William Ryan eMVP
Guest
Posts: n/a
 
      21st May 2004
Hi Ori:

--
W.G. Ryan MVP Windows - Embedded

www.devbuzz.com
www.knowdotnet.com
http://www.msmvps.com/williamryan/
"Ori" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I have a listbox which is bounded to a datatable. I allow the users to
> add/remove items from the list while adding/remove rows from the
> datatable which function as the datasource.
>
> When I come to do the "update" back to the datatbase using the
> SqlDataAdapter and the insert/delete command, I see that only the new
> rows are added and the old one doesn't. removed from the database.

--- There are a few things to look for .

How are you 'removing' the rows from your datatable
?http://www.knowdotnet.com/articles/efficient_pt4.html
Are you calling the .Remove method or the .Delete method? If you are
callling remove, then you are actually taking the rows out of the
colllection so when you call update, the Adapter doesn't even see these
rows, hence it has nothing to call against them. Delete on the other hand
doesn't do anything but change the rowstate on the row. So when the adapter
loops through the rows collection checking the Rowstate, it sees the .Delete
(d) rowstates and then uses those rows in conjuntion with your adapter's
delete commadn.

If you are calling .Delete, then make sure that you can not 'editing' ... do
this by calling .EndCurrentEdit. Another thign may be your Delete commadn.
Make sure it's configured properly and not raising any exceptions... many
times these are wrapped in a try catch block that's not responded to so it
is actually breaking but there's no indication of it b/c the exception
handler is eating it.

Another thing you may want to try, is right before the call to update,
ccreate a DataView on the bound table.

DataView dv = ListBoxstable.DefaultView;
dv.RowStateFilter = DataViewRowState.Deleted;
Debug.Assert(dv.Count > 0); //just to verify that you in fact have deleted
rows.

Let me know how what happens and we'll take it from there.

HTH,

Bill

>
> After a short investigation, I notice that if I remove the rows
> directly from the datatable the deletecommand doesn't have a row to
> operate on.
>
> Can someone explain me exactly how to use the delete command along
> with a binding to a listbox which you can remove and add items.
>
> Thanks,
>
> Ori.



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Propogate Updates Dominic Vella Microsoft Access 4 26th Sep 2008 08:22 PM
Propogate data between records =?Utf-8?B?QnVua3k=?= Microsoft Access 6 3rd Aug 2007 10:54 PM
Could not find <back end database path> database's startup message =?Utf-8?B?RG91Ymxl?= Microsoft Access VBA Modules 5 6th Jun 2007 12:38 AM
userform listbox cannot get listbox.value to transfer back to main sub malosky2@msn.com Microsoft Excel Programming 1 17th May 2006 10:44 PM
RE: Could not find <back end database path> database's startup message =?Utf-8?B?RG91Ymxl?= Microsoft Access VBA Modules 0 3rd Feb 2006 12:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:07 AM.