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."
>