PC Review


Reply
Thread Tools Rate Thread

Re: Update from Datasource to the database with sqlDataAdapter

 
 
William Ryan eMVP
Guest
Posts: n/a
 
      22nd May 2004
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>



 
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
Update more than 1 table in a DataSet using SqlDataAdapter.Update LP Microsoft VB .NET 3 13th Feb 2005 05:49 PM
Update more than 1 table in a DataSet using SqlDataAdapter.Update LP Microsoft ADO .NET 3 13th Feb 2005 05:49 PM
Re: Update from Datasource to the database with sqlDataAdapter Pete Wright Microsoft ADO .NET 0 22nd May 2004 09:20 PM
How to update the Database by using SqlDataAdapter object in asp.net? zhaoJian Microsoft ASP .NET 0 6th Nov 2003 04:06 AM
SqlDataAdapter.Update doesn't delete, will however insert and update, what gives? Andy Baldwin Microsoft ADO .NET 1 22nd Oct 2003 08:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:52 PM.