Mettre à jour la Table après modification d'un DatatGrid?
2 réponses
DP
Bonjour,
J'ai une table Access et un DataGrid.
Quand j'efface une ligne avec un bouton "Effacer", la ligne est bien
supprimée du GataGrid mais quand je relance l'application, la table
sous-jacente n'a pas étét mise à jour et les lignes "effacées" sont de
nouveau présentes.
Pourtant, Update ne signale aucene erreur.
Pouvez vous m'aider?
Merci
DP
Mon code
Private Sub cmdSupprimer_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdSupprimer.Click
Dim LigneChoisie As Integer
LigneChoisie = (DataGridListeActes.CurrentRowIndex)
Dim myRow As DataRow
myRow = dtsListeActes.Tables(strTable).Rows(LigneChoisie)
Me.dtsListeActes.Tables(strTable).Rows.Remove(myRow)
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Osman MALIK [MS]
Bonjour,
Votre problème vient probablement du fait que vous avez retiré la ligne de la DataRowCollection du DataSet sans indiquer qu'il fallait la supprimer. Dans le cas où le DataSet est connecté à une base relationnelle, il faut utiliser la méthode Delete afin de marquer la ligne comme devant être supprimée. Lors de la mise à jour du DataAdapter, ce dernier supprimera toutes les lignes marquées comme devant être à supprimer. Vous trouverez une explication dans cet article: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconDeletingDataRowFromDataTable.asp
Voici l'extrait correspondant à votre problème: When using a DataSet or DataTable in conjunction with a DataAdapter and a relational data source, use the Delete method of the DataRow to remove the row. The Delete method marks the row as Deleted in the DataSet or DataTable but does not remove it. Instead, when the DataAdapter encounters a row marked as Deleted, it executes its DeleteCommand to delete the row at the data source. The row can then be permanently removed using the AcceptChanges method. If you use Remove to delete the row, the row will be removed entirely from the table but the DataAdapter will not delete the row at the data source.
Cordialement, Osman MALIK
"DP" wrote in message news:
Bonjour,
J'ai une table Access et un DataGrid. Quand j'efface une ligne avec un bouton "Effacer", la ligne est bien supprimée du GataGrid mais quand je relance l'application, la table sous-jacente n'a pas étét mise à jour et les lignes "effacées" sont de nouveau présentes. Pourtant, Update ne signale aucene erreur. Pouvez vous m'aider?
Merci
DP
Mon code
Private Sub cmdSupprimer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSupprimer.Click
Dim LigneChoisie As Integer
LigneChoisie = (DataGridListeActes.CurrentRowIndex) Dim myRow As DataRow myRow = dtsListeActes.Tables(strTable).Rows(LigneChoisie) Me.dtsListeActes.Tables(strTable).Rows.Remove(myRow)
Me.odaListeActes.Update(dtsListeActes, strTable)
End Sub
Bonjour,
Votre problème vient probablement du fait que vous avez retiré la ligne de
la DataRowCollection du DataSet sans indiquer qu'il fallait la supprimer.
Dans le cas où le DataSet est connecté à une base relationnelle, il faut
utiliser la méthode Delete afin de marquer la ligne comme devant être
supprimée.
Lors de la mise à jour du DataAdapter, ce dernier supprimera toutes les
lignes marquées comme devant être à supprimer.
Vous trouverez une explication dans cet article:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconDeletingDataRowFromDataTable.asp
Voici l'extrait correspondant à votre problème:
When using a DataSet or DataTable in conjunction with a DataAdapter and a
relational data source, use the Delete method of the DataRow to remove the
row. The Delete method marks the row as Deleted in the DataSet or DataTable
but does not remove it. Instead, when the DataAdapter encounters a row
marked as Deleted, it executes its DeleteCommand to delete the row at the
data source. The row can then be permanently removed using the AcceptChanges
method. If you use Remove to delete the row, the row will be removed
entirely from the table but the DataAdapter will not delete the row at the
data source.
Cordialement,
Osman MALIK
"DP" <db3319nospam@serveurwanadoo.fr> wrote in message
news:eVAosNpFFHA.1264@TK2MSFTNGP12.phx.gbl...
Bonjour,
J'ai une table Access et un DataGrid.
Quand j'efface une ligne avec un bouton "Effacer", la ligne est bien
supprimée du GataGrid mais quand je relance l'application, la table
sous-jacente n'a pas étét mise à jour et les lignes "effacées" sont de
nouveau présentes.
Pourtant, Update ne signale aucene erreur.
Pouvez vous m'aider?
Merci
DP
Mon code
Private Sub cmdSupprimer_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdSupprimer.Click
Dim LigneChoisie As Integer
LigneChoisie = (DataGridListeActes.CurrentRowIndex)
Dim myRow As DataRow
myRow = dtsListeActes.Tables(strTable).Rows(LigneChoisie)
Me.dtsListeActes.Tables(strTable).Rows.Remove(myRow)
Votre problème vient probablement du fait que vous avez retiré la ligne de la DataRowCollection du DataSet sans indiquer qu'il fallait la supprimer. Dans le cas où le DataSet est connecté à une base relationnelle, il faut utiliser la méthode Delete afin de marquer la ligne comme devant être supprimée. Lors de la mise à jour du DataAdapter, ce dernier supprimera toutes les lignes marquées comme devant être à supprimer. Vous trouverez une explication dans cet article: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconDeletingDataRowFromDataTable.asp
Voici l'extrait correspondant à votre problème: When using a DataSet or DataTable in conjunction with a DataAdapter and a relational data source, use the Delete method of the DataRow to remove the row. The Delete method marks the row as Deleted in the DataSet or DataTable but does not remove it. Instead, when the DataAdapter encounters a row marked as Deleted, it executes its DeleteCommand to delete the row at the data source. The row can then be permanently removed using the AcceptChanges method. If you use Remove to delete the row, the row will be removed entirely from the table but the DataAdapter will not delete the row at the data source.
Cordialement, Osman MALIK
"DP" wrote in message news:
Bonjour,
J'ai une table Access et un DataGrid. Quand j'efface une ligne avec un bouton "Effacer", la ligne est bien supprimée du GataGrid mais quand je relance l'application, la table sous-jacente n'a pas étét mise à jour et les lignes "effacées" sont de nouveau présentes. Pourtant, Update ne signale aucene erreur. Pouvez vous m'aider?
Merci
DP
Mon code
Private Sub cmdSupprimer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSupprimer.Click
Dim LigneChoisie As Integer
LigneChoisie = (DataGridListeActes.CurrentRowIndex) Dim myRow As DataRow myRow = dtsListeActes.Tables(strTable).Rows(LigneChoisie) Me.dtsListeActes.Tables(strTable).Rows.Remove(myRow)
Me.odaListeActes.Update(dtsListeActes, strTable)
End Sub
DP
Bonsoir,
J'ai testé en remplaçant dtsListeActes.Tables(strTable).Rows.Remove(myRow) par myRow.Delete()
Mais cela me génère une erreur dont voici le texte : Une exception non gérée du type 'System Invalid Operation Exception' s'est produite dans System.data.dll Infos supp : La génération SQL dynamique pour le Delete Command n'est pas prise en charge pour un Select Command qui ne retourne pas des informations de colonne clé.
Pourtant, mon Select Commande retourne la colonne ID qui est la clé primaire de ma Table.
Qu'est-ce qui m'échappe?
Merci de votre aide.
DP
Bonsoir,
J'ai testé en remplaçant
dtsListeActes.Tables(strTable).Rows.Remove(myRow) par
myRow.Delete()
Mais cela me génère une erreur dont voici le texte :
Une exception non gérée du type 'System Invalid Operation Exception' s'est
produite dans System.data.dll
Infos supp : La génération SQL dynamique pour le Delete Command n'est pas
prise en charge pour un Select Command qui ne retourne pas des informations
de colonne clé.
Pourtant, mon Select Commande retourne la colonne ID qui est la clé primaire
de ma Table.
J'ai testé en remplaçant dtsListeActes.Tables(strTable).Rows.Remove(myRow) par myRow.Delete()
Mais cela me génère une erreur dont voici le texte : Une exception non gérée du type 'System Invalid Operation Exception' s'est produite dans System.data.dll Infos supp : La génération SQL dynamique pour le Delete Command n'est pas prise en charge pour un Select Command qui ne retourne pas des informations de colonne clé.
Pourtant, mon Select Commande retourne la colonne ID qui est la clé primaire de ma Table.