Transaction dans Vb.net

Résolu
eddyphan Messages postés 10 Date d'inscription samedi 25 août 2007 Statut Membre Dernière intervention 17 novembre 2012 - 6 juin 2012 à 16:50
eddyphan Messages postés 10 Date d'inscription samedi 25 août 2007 Statut Membre Dernière intervention 17 novembre 2012 - 12 juin 2012 à 10:17
salut,
Je veux enregistrer des données dans ma base via une transaction que je pense avoir bien fait.
Mon souci est que les modifications dans la base s'exécute par séquence (lorsque les première lignes s'exécutent et qu'il y a une erreur dans les lignes suivantes, au lieu de procéder à l'annulation (rollback), les données entrées dans la base y restent.

Veuillez m'aider svp.

Voici mon code :

  Dim SQLTransac As OdbcCommand = Nothing
        Dim Transac As OdbcTransaction = Nothing



        Try


            Transac = Connexion.BeginTransaction()

            SQLTransac = Connexion.CreateCommand()

            SQLTransac.Transaction = Transac

            SQLTransac.Connection = Connexion()



            ' insertion dans la table parent

            SQLTransac.CommandText = "Insert into VenteCptoire(CodVent,DateVent,dateenreg,CodDep,Depot,Vendeur,CodCli,Client,MttTTC,OptValider,OptEncaisser,OptFacturer,Caisse,optcomptabiliser,OptAnnuler)values ('" & Me.TextBox1.Text & "','" & Now.ToShortDateString & "','" & Now.ToShortDateString & "','" & PCodDepo & "','" & PDepot & "','" & PVendeur & "','" & Me.txtcodcli.Text & "','" & Trim(Me.ComboBox3.Text) & "','" & CDec(Me.txtttc.Text) & "','" & True & "','" & False & "','" & False & "','" & PCaisse & "','" & False & "','" & False & "')"
            SQLTransac.ExecuteNonQuery()
      

            'insertion dans la table enfant

            For i = 0 To Me.DataGridView1.Rows.Count - 1

                Dim row As DataGridViewRow = Me.DataGridView1.Rows(i)

                SQLTransac.CommandText = "Insert into dtlVenteCpt(CodVent0,CodArt,Article,QteVendu,PVU,Mtt)values ('" & Me.TextBox1.Text & "','" & Me.DataGridView1.Rows(i).Cells(0).Value & "','" & Me.DataGridView1.Rows(i).Cells(1).Value & "','" & Val(Me.DataGridView1.Rows(i).Cells(4).Value) & "','" & CDec(Me.DataGridView1.Rows(i).Cells(5).Value) & "','" & CDec(Me.DataGridView1.Rows(i).Cells(7).Value) & "')"
                SQLTransac.ExecuteNonQuery()

                Dim Mycommand2 As OdbcCommand = Connexion.CreateCommand()
                Mycommand2.CommandText "SELECT * FROM Mvt_VenteCaisse where dateop '" & Now.ToShortDateString & "' and CodArt = '" & Me.DataGridView1.Rows(i).Cells(0).Value & "' and CodeDep = '" & PCodDepo & "' and caisse = '" & PCaisse & "'"

                Dim myReader2 As OdbcDataReader = Mycommand2.ExecuteReader()
                If myReader2.HasRows = False Then
                    OptTV = False
                    SQLTransac.CommandText = "Insert into Mvt_VenteCaisse(dateop,CodeDep,Depot,codcaiss,caisse,marque,codfam,famille,CodArt,Article,Qtevendu,PVU,Mtt)values ('" & CDate(Me.MaskedTextBox1.Text) & "','" & PCodDepo & "','" & PDepot & "','" & PCodcaiss & "','" & PCaisse & "','" & Me.DataGridView1.Rows(i).Cells(10).Value & "','" & Me.DataGridView1.Rows(i).Cells(11).Value & "','" & Me.DataGridView1.Rows(i).Cells(12).Value & "','" & Me.DataGridView1.Rows(i).Cells(0).Value & "','" & Me.DataGridView1.Rows(i).Cells(1).Value & "','" & Val(Me.DataGridView1.Rows(i).Cells(4).Value) & "','" & CDec(Me.DataGridView1.Rows(i).Cells(5).Value) & "','" & CDec(Me.DataGridView1.Rows(i).Cells(7).Value) & "')"
                    SQLTransac.ExecuteNonQuery()
                Else
                    OptTV = True
                    SQLTransac.CommandText "Update Mvt_VenteCaisse set Qtevendu '" & Val(Me.DataGridView1.Rows(i).Cells(13).Value) & "' where CodArt = '" & Me.DataGridView1.Rows(i).Cells(0).Value & "' and famille = '" & Me.DataGridView1.Rows(i).Cells(12).Value & "' and caisse = '" & PCaisse & "' and Depot = '" & PDepot & "' and dateop = '" & Now.ToShortDateString & "'"
                    SQLTransac.ExecuteNonQuery()
                    SQLTransac.CommandText "Update Mvt_VenteCaisse set Mtt '" & CDec(Me.DataGridView1.Rows(i).Cells(7).Value) & "' where CodArt = '" & Me.DataGridView1.Rows(i).Cells(0).Value & "' and famille = '" & Me.DataGridView1.Rows(i).Cells(12).Value & "' and caisse = '" & PCaisse & "' and Depot = '" & PDepot & "' and dateop = '" & Now.ToShortDateString & "'"
                    SQLTransac.ExecuteNonQuery()

                End If


                myReader2.Close()
                SQLTransac.CommandText = "Insert into MVDepot(CodeMvt,CodeDep,CodArt,Article,Depot,PA,PVU,QteInitial,QteEntre,QteSortie,QteFinale,SensMvt,Observat,TypDepot,DateMv,DateEnreg)values ('" & Me.TextBox1.Text & "','Cood','" & Me.DataGridView1.Rows(i).Cells(0).Value & "','" & Me.DataGridView1.Rows(i).Cells(1).Value & "','" & PDepot & "','" & Val(Me.DataGridView1.Rows(i).Cells(6).Value) & "','" & CDec(Me.DataGridView1.Rows(i).Cells(5).Value) & "','" & Val(Me.DataGridView1.Rows(i).Cells(8).Value) & "',0,'" & Val(Me.DataGridView1.Rows(i).Cells(4).Value) & "','" & Val(Me.DataGridView1.Rows(i).Cells(9).Value) & "','Sortie','Vente Comptoire','Depot de Vente','" & Now.ToShortDateString & "','" & Now.ToShortDateString & "')"
                SQLTransac.ExecuteNonQuery()



            Next i


            SQLTransac.CommandText = "Insert into BrouillardCaisse(dateenreg,dateop,codCaiss,Caisse,Libelle,Entree,Sortie,solde) values ('" & Now.ToShortDateString & "','" & Pdate & "','" & PCodcaiss & "','" & PCaisse & "','vente au Comptoire Ticket N° " & Me.TextBox1.Text & "','" & Val(Me.txtttc.Text) & "',0, '" & Val(Me.txtttc.Text) & "')"
            SQLTransac.ExecuteNonQuery()
            SQLTransac.CommandText "Update VenteCptoire set MttTTC '" & CDec(Me.txtttc.Text) & "' where CodVent = '" & Me.TextBox1.Text & "'"
            SQLTransac.ExecuteNonQuery()

            SQLTransac.CommandText "Update VenteCptoire set MttPayer '" & CDec(Me.txtttc.Text) & "' where CodVent = '" & Me.TextBox1.Text & "'"
            SQLTransac.ExecuteNonQuery()


            Transac.Commit()
            Transac.Dispose()
            optvalider = False
            Me.Label22.Visible = True
            Me.Label22.Text = "vente effectuée avec succès.."

        Catch ex As Exception
            MsgBox("La Transaction a échouée.Aucun Mouvement n'a été effectué")
            MsgBox(Err.Description)

            Try

                Transac.Rollback()
                Transac.Dispose()

                Me.Close()
            Catch g As Exception
                MsgBox("Délai Dépassé, La Transaction sur les différents comptes a  échouée...")
                Me.Close()
            End Try
        End Try

16 réponses

foliv57 Messages postés 420 Date d'inscription vendredi 17 novembre 2006 Statut Membre Dernière intervention 15 juillet 2014 9
11 juin 2012 à 18:00
Si avec l'exemple de mon post précédent l'annulation fonctionne, il vous faudra faire ceci dans votre code

Dim SQLTransac As OdbcCommand = Nothing
Dim Transac As OdbcTransaction = Nothing
Dim maConnexion As OdbcConnection = Nothing
 
Try

   maConnexion = Connexion() 'Création et ouverture de la connexion
   Transac = maConnexion .BeginTransaction() 'Création et début de transaction

   SQLTransac = New OdbcCommand() 'Création d'une nouvelle commande
   SQLTransac.Connection = maConnexion 'On attache la connexion de la commande à la connexion créée précédement
   SQLTransac.Transaction = Transac 'On attache la transaction à la commande

   'Exécution des requêtes

   Transac.Commit()
   Transac.Dispose()
   optvalider = False
   Me.Label22.Visible = True
   Me.Label22.Text = "vente effectuée avec succès.."

Catch ex As Exception
   MsgBox("La Transaction a échouée.Aucun Mouvement n'a été effectué")
   MsgBox(Err.Description)

   Try

       Transac.Rollback()
       Transac.Dispose()
       Me.Close()
   Catch g As Exception
       MsgBox("Délai Dépassé, La Transaction sur les différents comptes a  échouée...")
       Me.Close()
   End Try
End Try
3
foliv57 Messages postés 420 Date d'inscription vendredi 17 novembre 2006 Statut Membre Dernière intervention 15 juillet 2014 9
9 juin 2012 à 13:53
Bonjour,

Quelle type de base de données utilisez vous ?
0
foliv57 Messages postés 420 Date d'inscription vendredi 17 novembre 2006 Statut Membre Dernière intervention 15 juillet 2014 9
9 juin 2012 à 13:56
D'avance, si c'est une base de données ACCESS. Elle ne supporte pas les transactions.
0
eddyphan Messages postés 10 Date d'inscription samedi 25 août 2007 Statut Membre Dernière intervention 17 novembre 2012
10 juin 2012 à 17:32
Merci foliv57,

J'utilise une base de données Sql Server 2008 en ODBC.
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
foliv57 Messages postés 420 Date d'inscription vendredi 17 novembre 2006 Statut Membre Dernière intervention 15 juillet 2014 9
10 juin 2012 à 18:36
Avez vous fait l'essai avec la bibliothèque

System.Data.SqlClient

plutot qu'odbc ?
0
foliv57 Messages postés 420 Date d'inscription vendredi 17 novembre 2006 Statut Membre Dernière intervention 15 juillet 2014 9
10 juin 2012 à 19:15
Si je ne me trompe pas, vous devriez avoir une erreur d'exécution

InvalidOperationException

ExecuteReader implique que la commande comporte une transaction
lorsque la connexion attribuée à la commande se trouve dans une 
transaction locale en attente. La propriété Transaction de la 
commande n'a pas été initialisée.


Ici
Dim Mycommand2 As OdbcCommand = Connexion.CreateCommand()
Mycommand2.CommandText = "..."

Dim myReader2 As OdbcDataReader = Mycommand2.ExecuteReader()


Car vous tentez d'exécuter une commande non rattachée à une transaction via une connexion avec transaction en attente.
0
foliv57 Messages postés 420 Date d'inscription vendredi 17 novembre 2006 Statut Membre Dernière intervention 15 juillet 2014 9
10 juin 2012 à 19:39
Il vous faut donc rattacher la commande de lecture à la transaction
Dim Mycommand2 As OdbcCommand = Connexion.CreateCommand()
Mycommand2.CommandText = "..."
Mycommand2.Transaction = Transac
Dim myReader2 As OdbcDataReader = Mycommand2.ExecuteReader()


Par contre, du coup, vous aurez un inter-verrouillage lors du deuxième passage dans la boucle for.

Il vous faudra donc fermer Mycommand2 et son reader avant d'exécuter les insert et update.

Dim Mycommand2 As OdbcCommand = Connexion.CreateCommand()
Mycommand2.CommandText = "..."
Mycommand2.Transaction = Transac
Dim myReader2 As OdbcDataReader = Mycommand2.ExecuteReader()
Dim myReaderHasRows as Boolean = myReader2.HasRows
myReader2 .Close()
Mycommand2.Dispose()

If myReaderHasRows  = False Then
  OptTV = False
  SQLTransac.CommandText = "..."
  SQLTransac.ExecuteNonQuery()
Else
  OptTV = True
  SQLTransac.CommandText = "..."
  SQLTransac.ExecuteNonQuery()
  SQLTransac.CommandText = "..."
  SQLTransac.ExecuteNonQuery()
End If

SQLTransac.CommandText = "..."
SQLTransac.ExecuteNonQuery()
0
eddyphan Messages postés 10 Date d'inscription samedi 25 août 2007 Statut Membre Dernière intervention 17 novembre 2012
11 juin 2012 à 11:38
Merci foliv pour toutes tes réponses.

Par rapport à la commande dans la boucle, je l'ai même enlevé finalement mais pareil. Tu demande si je l'ai essayé avec sqlclient. J'avais développé un autre projet dans lequel il y a transaction avec ça mais ça marchait sans soucis.

Est ce que tu penses que l'odbc ne supporte pas les transaction?

voici mon code après la suppression :

 Dim SQLTransac As OdbcCommand = Nothing
                                Dim Transac As OdbcTransaction = Nothing

                                SQLTransac = Connexion.CreateCommand()

                                SQLTransac.Transaction = Transac
                                SQLTransac.Connection = Connexion()

                                Try

                                    Transac = Connexion.BeginTransaction()

                                    ' insertion dans la table parent

                                    SQLTransac.CommandText = "Insert into VenteCptoire(CodVent,DateVent,dateenreg,CodDep,Depot,Vendeur,CodCli,Client,MttTTC,OptValider,OptEncaisser,OptFacturer,Caisse,optcomptabiliser,OptAnnuler)values ('" & Me.TextBox1.Text & "','" & Now.ToShortDateString & "','" & Now.ToShortDateString & "','" & PCodDepo & "','" & PDepot & "','" & PVendeur & "','" & Me.txtcodcli.Text & "','" & Trim(Me.ComboBox3.Text) & "','" & CDec(Me.txtttc.Text) & "','" & True & "','" & False & "','" & False & "','" & PCaisse & "','" & False & "','" & False & "')"
                                    SQLTransac.ExecuteNonQuery()


                                    'insertion dans la table enfant

                                    For i = 0 To Me.DataGridView1.Rows.Count - 1

                                        Dim row As DataGridViewRow = Me.DataGridView1.Rows(i)

                                        SQLTransac.CommandText = "Insert into dtlVenteCpt(CodVent,CodArt,Article,QteVendu,PVU,Mtt)values ('" & Me.TextBox1.Text & "','" & Me.DataGridView1.Rows(i).Cells(0).Value & "','" & Me.DataGridView1.Rows(i).Cells(1).Value & "','" & Val(Me.DataGridView1.Rows(i).Cells(4).Value) & "','" & CDec(Me.DataGridView1.Rows(i).Cells(5).Value) & "','" & CDec(Me.DataGridView1.Rows(i).Cells(7).Value) & "')"
                                        SQLTransac.ExecuteNonQuery()

                                        SQLTransac.CommandText = "Insert into MVDepot(CodeMvt,CodeDep,CodArt,Article,Depot,PA,PVU,QteInitial,QteEntre,QteSortie,QteFinale,SensMvt,Observat,TypDepot,DateMv,DateEnreg)values ('" & Me.TextBox1.Text & "','Cood','" & Me.DataGridView1.Rows(i).Cells(0).Value & "','" & Me.DataGridView1.Rows(i).Cells(1).Value & "','" & PDepot & "','" & Val(Me.DataGridView1.Rows(i).Cells(6).Value) & "','" & CDec(Me.DataGridView1.Rows(i).Cells(5).Value) & "','" & Val(Me.DataGridView1.Rows(i).Cells(8).Value) & "',0,'" & Val(Me.DataGridView1.Rows(i).Cells(4).Value) & "','" & Val(Me.DataGridView1.Rows(i).Cells(9).Value) & "','Sortie','Vente Comptoire','Depot de Vente','" & Now.ToShortDateString & "','" & Now.ToShortDateString & "')"
                                        SQLTransac.ExecuteNonQuery()



                                    Next i


                                    SQLTransac.CommandText = "Insert into BrouillardCaisse(dateenreg,dateop,codCaiss,Caisse,Libelle,Entree,Sortie,solde) values ('" & Now.ToShortDateString & "','" & Pdate & "','" & PCodcaiss & "','" & PCaisse & "','vente au Comptoire Ticket N° " & Me.TextBox1.Text & "','" & Val(Me.txtttc.Text) & "',0, '" & Val(Me.txtttc.Text) & "')"
                                    SQLTransac.ExecuteNonQuery()
                                    SQLTransac.CommandText "Update VenteCptoire set MttTTC '" & CDec(Me.txtttc.Text) & "' where CodVent = '" & Me.TextBox1.Text & "'"
                                    SQLTransac.ExecuteNonQuery()

                                    SQLTransac.CommandText "Update VenteCptoire set MttPayer '" & CDec(Me.txtttc.Text) & "' where CodVent = '" & Me.TextBox1.Text & "'"
                                    SQLTransac.ExecuteNonQuery()


                                    Transac.Commit()
                                    Transac.Dispose()
                                    optvalider = False
                                    Me.Label22.Visible = True
                                    Me.Label22.Text = "vente effectuée avec succès.."

                                Catch ex As Exception
                                    MsgBox("La Transaction a échouée.Aucun Mouvement n'a été effectué")
                                    MsgBox(Err.Description)

                                    Try

                                        Transac.Rollback()
                                       
                                        Transac.Dispose()

                                        Me.Close()
                                    Catch g As Exception
                                        MsgBox("Délai Dépassé, La Transaction sur les différents comptes a  échouée...")
                                        Me.Close()
                                    End Try
                                End Try
0
foliv57 Messages postés 420 Date d'inscription vendredi 17 novembre 2006 Statut Membre Dernière intervention 15 juillet 2014 9
11 juin 2012 à 13:20
Pour l'odbc c'est bon, j'ai fait des essais hier. Il supporte les transactions.

Si vous faite ceci :
Dim SQLTransac As OdbcCommand = Nothing
Dim Transac As OdbcTransaction = Connexion.BeginTransaction()

SQLTransac = Connexion.CreateCommand()
SQLTransac.Transaction = Transac

' insertion dans la table parent
SQLTransac.CommandText = "..."
SQLTransac.ExecuteNonQuery()

'insertion dans la table enfant
For i = 0 To Me.DataGridView1.Rows.Count - 1
   Dim row As DataGridViewRow = Me.DataGridView1.Rows(i)

   SQLTransac.CommandText = "Insert into dtlVenteCpt(..."
   SQLTransac.ExecuteNonQuery()

   SQLTransac.CommandText = "Insert into MVDepot(.."
   SQLTransac.ExecuteNonQuery()

Next i

SQLTransac.CommandText = "Insert into BrouillardCaisse(.."
SQLTransac.ExecuteNonQuery()

SQLTransac.CommandText = "Update VenteCptoire ..."
SQLTransac.ExecuteNonQuery()

SQLTransac.CommandText "Update VenteCptoire set MttPayer '..."
SQLTransac.ExecuteNonQuery()
                                  
Transac.Rollback()
Transac.Dispose()
Me.Close()


Y a-t-il des données enregistrées dans la base ?
0
eddyphan Messages postés 10 Date d'inscription samedi 25 août 2007 Statut Membre Dernière intervention 17 novembre 2012
11 juin 2012 à 13:58
wi,
si j'enlève le commit et utilise seulement le rollback, il y a toujours des insertions dans la base.
0
foliv57 Messages postés 420 Date d'inscription vendredi 17 novembre 2006 Statut Membre Dernière intervention 15 juillet 2014 9
11 juin 2012 à 15:13
Alors ça ce complique.

Pourriez vous poster votre chaîne de connexion à la base.

Avez vous exploré la piste des droits d'accès à vos tables. Je ne suis pas certain, mais si le compte n'as pas les droits en suppression, il ne peut peut-être pas rollbacker.

Car si en faisant ce simple test

Dim SQLTransac As OdbcCommand = Nothing
Dim Transac As OdbcTransaction = Connexion.BeginTransaction()

SQLTransac = Connexion.CreateCommand()
SQLTransac.Transaction = Transac

SQLTransac.CommandText = "INSERT INTO MaTable(MonChamp) VALUES ('Valeur')"
SQLTransac.ExecuteNonQuery()
                                  
Transac.Rollback()
Transac.Dispose()
SQLTransac.Dispose()


l'insertion n'est pas annulée, il y a de grande chance que cela provienne de droit car il n'y a pas d'erreur de code.
0
eddyphan Messages postés 10 Date d'inscription samedi 25 août 2007 Statut Membre Dernière intervention 17 novembre 2012
11 juin 2012 à 17:14
Merci pour tout une fois encore....
Voici la chaine de connexion à la base :

 Public Function Connexion() As OdbcConnection

        Try

           
            cs = "Dsn=PREMICIA;Uid=sa;Pwd=Secundia84;"
            Dim conn = New OdbcConnection(cs)


            conn.Open()

           
            Return conn
1:
        Catch tiex As TypeInitializationException
            MsgBox("Type non initialisé: " + tiex.TypeName)
            MsgBox("Message: " + tiex.InnerException.Message)

        Catch ex As Exception
            MsgBox("Autre exception: " + ex.Message)
        End Try
        Return Nothing
  
       
    End Function
0
foliv57 Messages postés 420 Date d'inscription vendredi 17 novembre 2006 Statut Membre Dernière intervention 15 juillet 2014 9
11 juin 2012 à 17:50
Ok, je crois voir le problème.

En faite, à chaque fois que vous appelez la fonction Connexion() vous créez une nouvelle connexion à la base.

Donc lorsque vous faite votre begintranscation, vous ne le faite pas sur la même connexion que l'OdbcCommand

Essayez ceci
Dim cs as String = "Dsn=PREMICIA;Uid=sa;Pwd=Secundia84;"
Using maConnexion as New OdbcConnection(cs)

   maConnexion .Open()
   Dim Transac As OdbcTransaction = maConnexion .BeginTransaction()
   
   Using SQLTransac as New OdbcCommand("Insert into VenteCptoire(CodVent...", maConnexion , Transac)
      
      SQLTransac.ExecuteNonQuery()
      Transac.Rollback()

   End Using
   
   Transac.Dispose()
End Using


Et dites moi si l'insertion est bien annulée
0
eddyphan Messages postés 10 Date d'inscription samedi 25 août 2007 Statut Membre Dernière intervention 17 novembre 2012
11 juin 2012 à 19:11
Merci beaucoup, je ne sais comment vous remercier. ça marche maintenant. Si je peux avoir votre numero, je vous appelerai pour vous remercier sincèrement.


                                Try

                                    Dim cs As String = "Dsn=PREMICIA;Uid=sa;Pwd=Secundia84;"
                                    Using maConnexion As New OdbcConnection(cs)

                                        maConnexion.Open()
                                        Dim Transac As OdbcTransaction = maConnexion.BeginTransaction()

                                        Using SQLTransac As New OdbcCommand("Insert into VenteCptoire(CodVent,DateVent,dateenreg,CodDep,Depot,Vendeur,CodCli,Client,MttTTC,OptValider,OptEncaisser,OptFacturer,Caisse,optcomptabiliser,OptAnnuler)values ('" & Me.TextBox1.Text & "','" & Now.ToShortDateString & "','" & Now.ToShortDateString & "','" & PCodDepo & "','" & PDepot & "','" & PVendeur & "','" & Me.txtcodcli.Text & "','" & Trim(Me.ComboBox3.Text) & "','" & CDec(Me.txtttc.Text) & "','" & True & "','" & False & "','" & False & "','" & PCaisse & "','" & False & "','" & False & "')", maConnexion, Transac)

                                            SQLTransac.ExecuteNonQuery()
                                            For i = 0 To Me.DataGridView1.Rows.Count - 1

                                                Dim row As DataGridViewRow = Me.DataGridView1.Rows(i)

                                                eddy = New OdbcCommand("Insert into dtlVenteCpt(CodVent,CodArt,Article,QteVendu,PVU,Mtt)values ('" & Me.TextBox1.Text & "','" & Me.DataGridView1.Rows(i).Cells(0).Value & "','" & Me.DataGridView1.Rows(i).Cells(1).Value & "','" & Val(Me.DataGridView1.Rows(i).Cells(4).Value) & "','" & CDec(Me.DataGridView1.Rows(i).Cells(5).Value) & "','" & CDec(Me.DataGridView1.Rows(i).Cells(7).Value) & "')", maConnexion, Transac)
                                                eddy.ExecuteNonQuery()

                                                eddy = New OdbcCommand("Insert into MVDepot(CodeMvt,CodeDep,CodArt,Article,Depot,PA,PVU,QteInitial,QteEntre,QteSortie,QteFinale,SensMvt,Observat,TypDepot,DateMv,DateEnreg)values ('" & Me.TextBox1.Text & "','Cood','" & Me.DataGridView1.Rows(i).Cells(0).Value & "','" & Me.DataGridView1.Rows(i).Cells(1).Value & "','" & PDepot & "','" & Val(Me.DataGridView1.Rows(i).Cells(6).Value) & "','" & CDec(Me.DataGridView1.Rows(i).Cells(5).Value) & "','" & Val(Me.DataGridView1.Rows(i).Cells(8).Value) & "',0,'" & Val(Me.DataGridView1.Rows(i).Cells(4).Value) & "','" & Val(Me.DataGridView1.Rows(i).Cells(9).Value) & "','Sortie','Vente Comptoire','Depot de Vente','" & Now.ToShortDateString & "','" & Now.ToShortDateString & "')", maConnexion, Transac)
                                                eddy.ExecuteNonQuery()



                                            Next i


                                            'eddy = New OdbcCommand("Insert into BrouillardCaisse(dateenreg,dateop,codCaiss,Caisse,Libelle,Entree,Sortie,solde) values ('" & Now.ToShortDateString & "','" & Pdate & "','" & PCodcaiss & "','" & PCaisse & "','vente au Comptoire Ticket N° " & Me.TextBox1.Text & "','" & Val(Me.txtttc.Text) & "',0, '" & Val(Me.txtttc.Text) & "')", maConnexion, Transac)

                                            'eddy.ExecuteNonQuery()

                                            eddy New OdbcCommand("Update VenteCptoire set MttTTC '" & CDec(Me.txtttc.Text) & "' where CodVent = '" & Me.TextBox1.Text & "'", maConnexion, Transac)

                                            eddy.ExecuteNonQuery()

                                            eddy New OdbcCommand("Update VenteCptoire set MttPayer '" & CDec(Me.txtttc.Text) & "' where CodVent = '" & Me.TextBox1.Text & "'", maConnexion, Transac)

                                            eddy.ExecuteNonQuery()
                                            Try
                                                Transac.Commit()

                                                MsgBox("Vente effectuée avec succès...")
                                                'maConnexion.Close()
                                                Me.Close()
                                            Catch ex As Exception
                                                Transac.Rollback()
                                                MsgBox("Transaction annulée.Vente non effectuée..")
                                                'maConnexion.Close()
                                                Me.Close()
                                            End Try
                                        End Using

                                        Transac.Dispose()

                                    End Using
                                Catch ex As Exception
                                    MsgBox(Err.Description)
                                End Try
0
foliv57 Messages postés 420 Date d'inscription vendredi 17 novembre 2006 Statut Membre Dernière intervention 15 juillet 2014 9
11 juin 2012 à 22:56
Pas de quoi.

Bonne continuation et bonne prog
0
eddyphan Messages postés 10 Date d'inscription samedi 25 août 2007 Statut Membre Dernière intervention 17 novembre 2012
12 juin 2012 à 10:17
merci
0
Rejoignez-nous