PC Review


Reply
Thread Tools Rate Thread

Cannot Delete Rows in Database

 
 
=?Utf-8?B?U2NvdHQ=?=
Guest
Posts: n/a
 
      15th Feb 2005
Hi all,

I am using the following to remove a row from a DataSet:
myDataSet.Tables["Table1"].Rows.RemoveAt(indexSelected);

followed by;
myDataAdapter.Update(myDataSet);

After this call, looking in the database, the row is not deleted. But
debugging it I can see it remove the row.

Also note that the following insert does insert into the database:
myDataSet.Tables["Table1"].Rows.InsertAt(newRow, index);

Strange how InsertAt works but not RemoveAt.

Does anyone knows what the problem is????

Thanks for any help,
Scott
 
Reply With Quote
 
 
 
 
geeksgk@yahoo.com
Guest
Posts: n/a
 
      16th Feb 2005
Do you mean to say it removed the row from the table when you debugged
it? (or removed it from the data table?)

Try using AcceptChanges method before updating the dataset.

 
Reply With Quote
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      16th Feb 2005
Hi Scott,

Use DataRow.Delete instead of Remove[At].
The difference is that Remove[At] removes row from collection, while Delete
marks is as Deleted and it is picked by Update for deleting.
And don't call AcceptChanges before Update. Actually you don't have to call
AcceptChanges at all in your scenario.
(AcceptChanges consolidates RowState of all rows to Unchanged).

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
SLODUG - Slovene Developer Users Group www.codezone-si.info

"Scott" <(E-Mail Removed)> wrote in message
news:953A3FC0-1599-4150-9A9E-(E-Mail Removed)...
> Hi all,
>
> I am using the following to remove a row from a DataSet:
> myDataSet.Tables["Table1"].Rows.RemoveAt(indexSelected);
>
> followed by;
> myDataAdapter.Update(myDataSet);
>
> After this call, looking in the database, the row is not deleted. But
> debugging it I can see it remove the row.
>
> Also note that the following insert does insert into the database:
> myDataSet.Tables["Table1"].Rows.InsertAt(newRow, index);
>
> Strange how InsertAt works but not RemoveAt.
>
> Does anyone knows what the problem is????
>
> Thanks for any help,
> Scott



 
Reply With Quote
 
=?Utf-8?B?U2NvdHQ=?=
Guest
Posts: n/a
 
      17th Feb 2005
Hi Miha,

Thank you!
That was the problem.

"Miha Markic [MVP C#]" wrote:

> Hi Scott,
>
> Use DataRow.Delete instead of Remove[At].
> The difference is that Remove[At] removes row from collection, while Delete
> marks is as Deleted and it is picked by Update for deleting.
> And don't call AcceptChanges before Update. Actually you don't have to call
> AcceptChanges at all in your scenario.
> (AcceptChanges consolidates RowState of all rows to Unchanged).
>
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & development
> www.rthand.com
> SLODUG - Slovene Developer Users Group www.codezone-si.info
>
> "Scott" <(E-Mail Removed)> wrote in message
> news:953A3FC0-1599-4150-9A9E-(E-Mail Removed)...
> > Hi all,
> >
> > I am using the following to remove a row from a DataSet:
> > myDataSet.Tables["Table1"].Rows.RemoveAt(indexSelected);
> >
> > followed by;
> > myDataAdapter.Update(myDataSet);
> >
> > After this call, looking in the database, the row is not deleted. But
> > debugging it I can see it remove the row.
> >
> > Also note that the following insert does insert into the database:
> > myDataSet.Tables["Table1"].Rows.InsertAt(newRow, index);
> >
> > Strange how InsertAt works but not RemoveAt.
> >
> > Does anyone knows what the problem is????
> >
> > Thanks for any help,
> > Scott

>
>
>

 
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
Autofil on variable rows, delete extract and show remaining rows 1plane Microsoft Excel Programming 3 17th Nov 2009 10:49 AM
Hpw do I delete multiple empty rows found between filled rows? Bill Microsoft Excel Worksheet Functions 1 15th Nov 2009 12:52 AM
Copy pasting Rows, but need to Delete any Shapes/Pictures that are within copied rows Corey Microsoft Excel Programming 2 1st Aug 2007 02:02 AM
Cut filtered rows, paste into next empty row of new sheet, and delete cut rows Scott Microsoft Excel Worksheet Functions 0 13th Dec 2006 01:25 AM
Delete rows with numeric values, leave rows with text =?Utf-8?B?R1NwbGluZQ==?= Microsoft Excel Programming 5 11th Oct 2005 12:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:21 AM.