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

Re: Cannot Delete Rows in Database by geeksgk

geeksgk
Tue Feb 15 19:56:16 CST 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.


Re: Cannot Delete Rows in Database by Miha

Miha
Wed Feb 16 02:15:38 CST 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" <Scott@discussions.microsoft.com> wrote in message
news:953A3FC0-1599-4150-9A9E-5600D64D1487@microsoft.com...
> 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



Re: Cannot Delete Rows in Database by Scott

Scott
Thu Feb 17 14:49:14 CST 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" <Scott@discussions.microsoft.com> wrote in message
> news:953A3FC0-1599-4150-9A9E-5600D64D1487@microsoft.com...
> > 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
>
>
>