bonjour tout le monde ;
j'ai un problème d'ajout , supp et modification .j'espère que quelqu'un peut me venir en aide
la table
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
21
22
23
24
25
26
27
28
29
30
31
create database DBcadre
go 
 
use DBcadre 
go 
if exists (select 1
            from  sysobjects
           where  id = object_id('CADRE')
            and   type = 'U')
   drop table CADRE
go
/*==============================================================*/
/* Table : CADRE                                                */
/*==============================================================*/
create table CADRE (
   NUM_CADRE            int             null,
   NUM_SERIE           varchar(30)                  not null   primary key  ,
   NOM_CADRE            varchar(30)                  null,
   NOM_CARTE          varchar(30)                  null,
   NBRE_CYCLE           varchar(30)               null,
   NBRE_MAX_CYCLE     varchar(30)              null,
   DUREE_DE_VIE         varchar(30)                 NULL,
   DATE_FAB            date                null,
   DATE_MISE_HS         date                 null,
   UF                   varchar(30)                  null,
   LIGNE                varchar(30)                  null,
   PHOTO                image                null,
   NOTE                 varchar(30)                  null,
 
)
go


mon code
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
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
Public Class Form1
 
 
 
 
    Dim cpt As String
    Sub New(ByVal str As String)
        '  Cet appel est requis par le Concepteur Windows Form.
        InitializeComponent()
 
        '    Ajoutez une initialisation quelconque après l'appel InitializeComponent().
        cpt = str
    End Sub
 
    Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO*: cette ligne de code charge les données dans la table 'DBcadreDataSet.CADRE'. Vous pouvez la déplacer ou la supprimer selon vos besoins.
        Me.CADRETableAdapter.Fill(Me.DBcadreDataSet.CADRE)
 
 
        If cpt = "A" Then
            CB_NumSerie.DropDownStyle = ComboBoxStyle.Simple
            BTN_Enregistrer.Text = "Ajouter"
        ElseIf cpt = "M" Then
            CB_NumSerie.DropDownStyle = ComboBoxStyle.DropDownList
            BTN_Enregistrer.Text = "Modifier"
        ElseIf cpt = "S" Then
            CB_NumSerie.DropDownStyle = ComboBoxStyle.DropDownList
            BTN_Enregistrer.Text = "Supprimer"
 
        End If
 
 
 
    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_Sortir.Click
        Me.Close()
    End Sub
 
 
    Private Sub BTN_Enregistrer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_Enregistrer.Click
        If BTN_Enregistrer.Text = "Ajouter" Then
            Try
                cmd.CommandText = "insert into cadre (" & " NUM_CADRE,NUM_SERIE,NOM_CADRE,DUREE_DE_VIE,NBRE_MAX_CYCLE,DATE_FAB,DATE_MISE_HS,UF " & ") VALUES (" & TxtNumCadre.Text & ",' " & CB_NumSerie.Text & "','" & TxtNomCadre.Text & "','" & TxtDuréeVie.Text & "','" & TxtNbreMaxVague.Text & "','" & txtDateFab.Text & "','" & TxtDateHS.Text & "','" & TxtUF.Text & "'" & ")"
                da.SelectCommand = cmd
                cmd.Connection = cnx
                '  da.Fill(ds, "CADRE")
                Dim nvlg As DataRow
                nvlg = ds.Tables("CADRE").NewRow
                nvlg("NUM_CADRE") = TxtNumCadre.Text
                nvlg(" NUM_SERIE") = CB_NumSerie.Text
                nvlg("NOM_CADRE") = TxtNomCadre.Text
                nvlg("NOM_CARTE") = TxtNomCarte.Text
                nvlg(" DUREE_DE_VIE") = TxtDuréeVie.Text
                nvlg("NBRE_MAX_CYCLE") = TxtNbreMaxVague.Text
                nvlg("DATE_FAB ") = txtDateFab.Text
                nvlg("DATE_MISE_HS ") = TxtDateHS.Text
                nvlg("UF") = TxtUF.Text
                ds.Tables("CADRE").Rows.Add(nvlg)
            Catch ex As Exception
                MsgBox(ex.Message)
 
            End Try
        ElseIf BTN_Enregistrer.Text = "Modifier" Then
            For Each nvlg In ds.Tables("CADRE").Rows
                If nvlg("Num_serie") = CB_NumSerie.SelectedValue Then
                    nvlg("NUM_CADRE") = TxtNumCadre.Text
                    nvlg("NOM_CADRE") = TxtNomCadre.Text
                    nvlg("NOM_CARTE") = TxtNomCarte.Text
                    nvlg("DUREE_DE_VIE") = TxtDuréeVie.Text
                    nvlg("NBRE_MAX_CYCLE") = TxtNbreMaxVague.Text
                    nvlg("DATE_FAB ") = txtDateFab.Text
                    nvlg("DATE_MISE_HS ") = TxtDateHS.Text
                    nvlg("UF") = TxtUF.Text
 
                End If
                cmd.CommandText = "update cadre set Num_cadre='" & TxtNumCadre.Text & "',NOM_CADRE='" & TxtNomCadre.Text & "',DUREE_DE_VIE ='" & TxtDuréeVie.Text & "'NBRE_MAX_CYCLE = " & TxtNbreMaxVague.Text & "'DATE_FAB =" & txtDateFab.Text & "' DATE_MISE_HS =" & TxtDateHS.Text & "' UF= " & TxtUF.Text & "' where NUM_SERIE = " & CB_NumSerie.SelectedValue
                da.SelectCommand = cmd
                cmd.Connection = cnx
                '  da.Fill(ds, "CADRE")
            Next
        Else : BTN_Enregistrer.Text = "Supprimer "
 
            If MessageBox.Show("voulez vous vraiment supprimer l'enregistrement", "confirmation", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
                For Each nvlg In ds.Tables("CADRE").Rows
                    If nvlg("NUM_SERIE") = CB_NumSerie.SelectedValue Then
                        cmd.CommandText = "delete from  CADRE where NUM_SERIE = " & CB_NumSerie.SelectedValue
                        da.SelectCommand = cmd
                        cmd.Connection = cnx
                        da.Fill(ds, "CADRE")
                        ds.Tables("CADRE").Rows.Remove(nvlg)
 
                        Exit For
                    End If
                    TxtNomCadre.Text = Nothing
                    TxtNumCadre.Text = Nothing
                    TxtUF.Text = Nothing
                    TxtNomCarte.Text = Nothing
                    TxtDuréeVie = Nothing
                    TxtNbreMaxVague.Text = Nothing
 
                Next
            Else : MessageBox.Show("suppression annuleé")
            End If
 
        End If
    End Sub
 
    Private Sub CB_NumSerie_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
 
        For Each nvlg In ds.Tables("CADRE").Rows
            If nvlg("NUM_SERIE") = CB_NumSerie.SelectedValue Then
                TxtNumCadre.Text = nvlg("NUM_CADRE")
                TxtNomCadre.Text = nvlg("NOM_CADRE")
                TxtNomCarte.Text = nvlg("NOM_CARTE")
                TxtDuréeVie.Text = nvlg(" DUREE_DE_VIE")
                TxtNbreMaxVague.Text = nvlg("NBRE_MAX_CYCLE")
                txtDateFab.Text = nvlg("DATE_FAB")
                TxtDateHS.Text = nvlg("DATE_MISE_HS")
                TxtUF.Text = nvlg("UF")
 
            End If
        Next
    End Sub
End Class
j'arrive pas a remplir les champs lors de la sélection d'un num série
ni a faire l'ajout ou la suppression ou la modification

lors de l'ajout par exp un message d'erreur indique que le num serie n'appartient pas à la table cadre !!!


quelqu'un peut m'aider