Hi Ori:
Like Pete mentioned, it's impossible to tell for sure without looking at the
code, but from the words you use I have a pretty good guess as to what your
problem is. .Delete and .Remove are two totally different methods. .Delete
marks your rows with a Deleted Rowstate. Remove takes them out of the
collection. If you have 100 rows, delete 50 of them and check your row
count before update (or callling AcceptChanges), you'll still have 100 rows.
If you do the same with remove you'll have 50. I have some examples here
http://www.knowdotnet.com/articles/efficient_pt4.html
Anyway, if your bindings are set up correctly, and you delete a row, you
should be fine. If you delete the records in the datatable directly you
will be fine too (provided you call update and it completes successfully).
another thing you can check is the RowStateFilter and set it to Added,
Modified and Deleted (create a DataView on the table and this is very easy
to check
http://www.knowdotnet.com/articles/dataviews1.html). You can also
just call update on those rows but the main value of doing this is so that
you can see what's changed (you can also loop through everything but it's a
bit more work.)
So, if you have a listBox and you want to remove Item 20 (assuming it's
bound to a DataTable dtt) you can check the SelectedIndex for instance
(which will be 20 in my example)
dtt.Rows[cboWhatever.SelectedIndex].Delete(); //You can do this with a
context menu for instance or any other UI cue you want. If you are using a
BindingContext directly, you can also call .Remove (which is effecitvely the
opposite of .AddNew)
Hopefully this explains it, but if not, please let me know.
http://www.knowdotnet.com/articles/dataviews1.html
Cheers,
Bill
--
W.G. Ryan, eMVP
http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
"Ori Anavim via .NET 247" <(E-Mail Removed)> wrote in message
news:e%(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.
>
> 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.
>
>
> --------------------------------
> From: Ori Anavim
>
> -----------------------
> Posted by a user from .NET 247 (http://www.dotnet247.com/)
>
> <Id>6Z0phwcpukajpwngCx+Jyw==</Id>