erreur une exception non gérée s'est produite vb.net

HOUSSEM MAHJOUBI 286 Reputation points
2020-10-16T09:48:44.337+00:00

bonjour members
j'ai un programme qui fait une mise à jour au stock
au cours d'execution a met cet erreur que je ne caonnait pas le source ou comment je le resoudre ce erreur voicie un photo d'erreur
32942-sans-titre1.png

voicie mon code
If cn.State = ConnectionState.Open Then
cn.Close()
End If
cn.Open()

        Dim cmd As New SqlCommand("select Codearticle,Numseq,Qte,PrixUnitaire,PrixRevient,Designation from DetailReceptionFrs where Numero='ST200036' order by numseq", cn)  
        'With cmd.Parameters  
        '    .Add("@Numero", SqlDbType.NVarChar).Value = (DataGridView1.Rows(i).Cells(1).Value)  
        'End With  
        Dim zz23 As New DataTable  
        Dim az As New SqlDataAdapter(cmd)  
        az.Fill(zz23)  
        Dim cmdDLigne245 As New SqlCommand("select DO_Piece,AR_Ref,DL_Ligne,Numseq,Qte from DL_Ligne_Table where Numero='ST200036' order by numseq ", cn)  
        Dim daz2456 As New SqlDataAdapter(cmdDLigne245)  
        Dim qqs2 As New DataTable  
        daz2456.Fill(qqs2)  
        For o = 0 To qqs2.Rows.Count - 1  
            Dim PrixRevient2 As Double = 0  
            '  PrixUnitaire = zz.Rows(o).Item(3)  
            PrixRevient2 = FormatNumber(CDbl(zz23.Rows(o).Item(4)), 3)  
            ' MessageBox.Show("article deta " & zz.Rows(o).Item(0) & "article dl " & qqs2.Rows(o).Item(1).ToString())  
            Dim articleEntrer = qqs2.Rows(o).Item(1).ToString()  
  
            If cn.State = ConnectionState.Open Then  
                cn.Close()  
            End If  
            cn.Open()  
  
            Dim asv As New SqlCommand("select as_qtesto,as_montsto,cbmarq from f_artstock where ar_ref='" & Trim(articleEntrer) & "' And de_no ='" & CInt(TextBox1.Text) & "' ", cn)  
  
  
            Dim qteEx As SqlDataReader = asv.ExecuteReader  
            qteEx.Read()  
  
  
  
            '  qte1 = qteEx(0) 'qte commandé  
            Dim qte2 = qteEx(0) 'qte stock  
            Dim qte3 = qteEx(1) 'montant  
            Dim cbmarq = qteEx(2)  
            Dim QteEntre As Double  
            QteEntre = zz23.Rows(o).Item(2)  
            '   Dim qteTotaleCom = qte1 - QteEntre  
            Dim qteTotaleSto = qte2 + QteEntre  
  
            Dim totMont = qte3 + PrixRevient2 * CDbl(zz23.Rows(o).Item(2))  
  
            If cn.State = ConnectionState.Open Then  
                cn.Close()  
            End If  
            cn.Open()  
            ' MessageBox.Show("Article " & articleEntrer & "AS_QteSto=" & qteTotaleSto & "AS_MontSto=" & totMont & " cbmarq=" & cbmarq)  
            Dim updF As New SqlCommand("UPDATE F_ARTSTOCK set  as_qtecom='0',AS_QteSto='" & qteTotaleSto & "',AS_MontSto='" & totMont & "' where cbmarq='" & cbmarq & "' ", cn)  
            updF.ExecuteNonQuery()  
            ' sr2.Write("Mise à jour de STOCK :" & articleEntrer & "  as_qtecom='0'" & " AS_QteSto = " & qteTotaleSto & " AS_MontSto = " & totMont & ": ok" & Environment.NewLine)  
            If cn.State = ConnectionState.Open Then  
                cn.Close()  
            End If  
            cn.Open()  
            Dim updF2 As New SqlCommand("UPDATE F_ARTICLE set  AR_PUNet='" & PrixRevient2 & "' where AR_REF= '" & Trim(articleEntrer) & "' ", cn)  
            updF2.ExecuteNonQuery()  
            ' sr2.Write("Mise à jour de F_ARTICLE  de l'article : " & articleEntrer & " AR_PUNet = " & PrixRevient2 & ": ok" & Environment.NewLine)  
  
        Next  
  
  
  
  
  
        Dim disArt As New SqlCommand("select DISTINCT(AR_REF) from DL_Ligne_Table where numero='ST200036'", cn)  
        Dim vis As New SqlDataAdapter(disArt)  
        Dim tabArt As New DataTable  
        vis.Fill(tabArt)  
        Dim articleDistinct As String  
  
        If cn.State = ConnectionState.Open Then  
            cn.Close()  
        End If  
        cn.Open()  
        For ab = 0 To tabArt.Rows.Count - 1  
            articleDistinct = tabArt.Rows(ab).Item("AR_REF").ToString  
            Dim arttrouve As New SqlCommand("select count(DL_Qte) FROM F_DOCLIGNE WHERE do_type='12' and ar_ref='" & Trim(articleDistinct) & "'", cn)  
            Dim trouveArt = arttrouve.ExecuteScalar  
            If trouveArt > 0 Then  
  
                If cn.State = ConnectionState.Open Then  
                    cn.Close()  
                End If  
                cn.Open()  
                Dim QteDocL As New SqlCommand("select SUM(DL_Qte) from F_DOCLIGNE where do_type='12' and ar_ref='" & Trim(articleDistinct) & "'", cn)  
                Dim sumQte As SqlDataReader = QteDocL.ExecuteReader  
                sumQte.Read()  
                Dim sumQteArt As Double  
                sumQteArt = sumQte(0)  
                If cn.State = ConnectionState.Open Then  
                    cn.Close()  
                End If  
                cn.Open()  
                Dim UpdateArticle As New SqlCommand("UPDATE F_ARTSTOCK SET AS_QteCom='" & sumQteArt & "' where AR_REF='" & Trim(articleDistinct) & "' and de_no='" & CInt(TextBox1.Text) & "'", cn)  
  
                UpdateArticle.ExecuteNonQuery()  
  
                'sr2.Write("Mise à jour de QteCommandé F_ARTSTOCK " & " Article = " & articleDistinct & " AS_QteCom = " & sumQteArt & ": ok" & Environment.NewLine)  
  
  
            End If  
        Next  
        cn.Close()  
        cn.Open()  
        Using cmd5 As New SqlCommand("update EnteteReceptionFrs set Etat='V' where Numero='ST200036' ", cn)  
            cmd5.ExecuteNonQuery()  
        End Using  
  
  
        If cn.State = ConnectionState.Open Then  
            cn.Close()  
        End If  
        cn.Open()  
        Using comm As New SqlCommand("delete from DL_Ligne_Table where Numero='ST200036'", cn)  
            comm.ExecuteNonQuery()  
        End Using  
        MessageBox.Show("Mise à jour terminée !!!")  
  
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
38,759 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.