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
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionInvalidOperationException 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.
Dim Mycommand2 As OdbcCommand = Connexion.CreateCommand() Mycommand2.CommandText = "..." Dim myReader2 As OdbcDataReader = Mycommand2.ExecuteReader()
Dim Mycommand2 As OdbcCommand = Connexion.CreateCommand() Mycommand2.CommandText = "..." Mycommand2.Transaction = Transac Dim myReader2 As OdbcDataReader = Mycommand2.ExecuteReader()
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()
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
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()
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()
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
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
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