Hi All!

After a long time for trying understand how strongly typed dataser
work, I've finaly success. Except on the delete command. When I do some
deleting, it only delete record from the dataset but not from the database.
I've try many thing but I turn arround. I paste you the code I use.

Me.cnAlbums.Open()
Dim Row As DsAlbums.PhotoRow =
Me.DsAlbums.Photo.FindByPhotoId(CInt(Me.lblPhotoId.Text))
Me.DsAlbums.Photo.RemovePhotoRow(Row)
Me.UpdateFlag = False
Me.DaPhoto.Update(Me.DsAlbums, "Photo") ' There is where it's suppose to
delete..?
Me.UpdateFlag = True
Me.cnAlbums.Close()

Sorry for my english but I'm french and I didn't get any response on the
french newsgroup

Thank a lot,
Francois

RE: Deleting In Strongly typed Dataset by v-kevy

v-kevy
Wed Feb 18 20:53:09 CST 2004

Hi Francois,

Thank you for posting in the community!

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to update the data source with
a certain DataTable. However, the deleted row wasn't updated correctly in
the data source. If there is any misunderstanding, please feel free to let
me know.

Based on the code you have provided, it seems that you have used the wrong
method to deleted a certain row. The RemovePhotoRow method actually calls
DataRowCollection.Remove method to detach the row from the collection. It
makes the row no longer belongs to any DataTable and the RowState property
is set to Detached. So when you call DataAdapter.Update method, the
DataAdapter loop through the whole row collection in the DataTable and
didn't find that row, because the row has been removed and wasn't in the
collection.

So when we want to delete a row, we have to use the DataRow.Delete method.
The DataRow.Delete method will set the RowState property of that row to
Deleted and when updates, the row will be removed both in the DataTable and
data source. Here I have made some changes to your code. Hope this helps.

'We needn't open and close connection explicitly, the DataAdapter will do
it for you.
Dim Row As DsAlbums.PhotoRow =
Me.DsAlbums.Photo.FindByPhotoId(CInt(Me.lblPhotoId.Text))
Row.Delete()
Me.UpdateFlag = False
Me.DaPhoto.Update(Me.DsAlbums, "Photo")
Me.UpdateFlag = True

For more information about DataRowCollection.Remove and DataRow.Delete
method, please check the following link for reference:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemdatadatarowcollectionclassremovetopic.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemDataDataRowClassDeleteTopic.asp

Does this answer your question? If anything is unclear, please feel free to
reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."


Re: Deleting In Strongly typed Dataset by Francois

Francois
Wed Feb 18 21:36:52 CST 2004

Hi Kevin,

Thank a lot for your post! That was exactly what I need! It work
perfectly!

Thank again,
Francois

"Kevin Yu [MSFT]" <v-kevy@online.microsoft.com> wrote in message
news:$q$1TOp9DHA.3024@cpmsftngxa07.phx.gbl...
> Hi Francois,
>
> Thank you for posting in the community!
>
> First of all, I would like to confirm my understanding of your issue. From
> your description, I understand that you need to update the data source
with
> a certain DataTable. However, the deleted row wasn't updated correctly in
> the data source. If there is any misunderstanding, please feel free to let
> me know.
>
> Based on the code you have provided, it seems that you have used the wrong
> method to deleted a certain row. The RemovePhotoRow method actually calls
> DataRowCollection.Remove method to detach the row from the collection. It
> makes the row no longer belongs to any DataTable and the RowState property
> is set to Detached. So when you call DataAdapter.Update method, the
> DataAdapter loop through the whole row collection in the DataTable and
> didn't find that row, because the row has been removed and wasn't in the
> collection.
>
> So when we want to delete a row, we have to use the DataRow.Delete method.
> The DataRow.Delete method will set the RowState property of that row to
> Deleted and when updates, the row will be removed both in the DataTable
and
> data source. Here I have made some changes to your code. Hope this helps.
>
> 'We needn't open and close connection explicitly, the DataAdapter will do
> it for you.
> Dim Row As DsAlbums.PhotoRow =
> Me.DsAlbums.Photo.FindByPhotoId(CInt(Me.lblPhotoId.Text))
> Row.Delete()
> Me.UpdateFlag = False
> Me.DaPhoto.Update(Me.DsAlbums, "Photo")
> Me.UpdateFlag = True
>
> For more information about DataRowCollection.Remove and DataRow.Delete
> method, please check the following link for reference:
>
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
> frlrfsystemdatadatarowcollectionclassremovetopic.asp
>
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
> frlrfSystemDataDataRowClassDeleteTopic.asp
>
> Does this answer your question? If anything is unclear, please feel free
to
> reply to the post.
>
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>



Re: Deleting In Strongly typed Dataset by v-kevy

v-kevy
Thu Feb 19 00:55:55 CST 2004

Hi Francois,

You're welcome. If you have any questions, please feel free to post them in
the community. I'm glad if I can help.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."