bonjour,
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
con.ConnectionString = "Data Source=MEHDI-PC\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=eco"
        d = CDate(MaskedTextBox1.Text)
        con.Open()
        cmd = New SqlCommand("select N_CPT_POS from COMPTEURS;", con)
        da = cmd.ExecuteReader
        While da.Read
            If da(0) = Val(TextBox13.Text) Then
                MsgBox("Un compteur avec le même numéro existe déja!", MsgBoxStyle.Critical)
                da.Close()
            Else
                Try
                    com = New SqlCommand("insert into COMPTEURS(N_ORD_ECO,SOUS_QUART,CIL,QUART,NOM_CLT,AV_ACC,PORTE,RUE,N_CPT_DEPO,N_SERIE,DER_IND_LU,TP_CAL,MAR_DEPO,N_CPT_POS,IND_DEPO,DATE_DEPO,CAL_POS,MAR_POS) values('" & ComboBox1.SelectedItem.ToString & "','" & TextBox1.Text & "','" & Val(TextBox2.Text) & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & Val(TextBox6.Text) & "','" & TextBox7.Text & "','" & Val(TextBox8.Text) & "','" & Val(TextBox9.Text) & "','" & Val(TextBox10.Text) & "','" & Val(TextBox11.Text) & "','" & TextBox12.Text & "','" & Val(TextBox13.Text) & "','" & Val(TextBox14.Text) & "','" & d & "','" & Val(TextBox16.Text) & "','" & TextBox17.Text & "''" & RichTextBox1.Text & "');", con)
                    com.ExecuteNonQuery()
                    MsgBox("Compteur ajouté avec succés", MsgBoxStyle.OkOnly)
                Catch ex As Exception
                    MsgBox("Erreur d'insertion des données:" & ex.ToString)
                End Try
            End If
        End While
        con.Close()
lorsque j'insère une donnée qui n'existe pas le message d'erreur que j'ai est:
un datareader associé à cette commande est déjà ouvert et doit être ferme