IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Problème pour éditer un datagridview&BDD


Sujet :

VB.NET

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Février 2011
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2011
    Messages : 14
    Par défaut Problème pour éditer un datagridview&BDD
    Bonjour,

    J'essaye en ce moment de créer un programme pour gérer des personnes/structures dans une base de données.

    L'ajout et la suppression fonctionnent bien, mais j'ai un problème pour éditer.

    J'ai plusieurs associations qui deviennent tables, donc j'ai rajouté aux contraintes des " update on cascade & delete on cascade " ( Histoire de pouvoir modifier/supprimer sur le datagrid et que ça puisse se répercuter sur les autres tables sans requête faramineuses ).

    Depuis ce moment là, l'édit ne marche plus, alors qu'il me semblait marcher avant ...

    Je vous donne le code de la fonction édit pour une structure

    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
     Case Is = strchx.Struc
     
     
     
                            Dim MyEditRow As DataRow = Dataset1.Tables(strchoix).Rows(DataGrid1.CurrentRow.Index)
                            MyEditRow.BeginEdit()
                            MyEditRow("nomstruc") = TextBox1.Text
                            MyEditRow("libstruc") = TextBox2.Text
                            MyEditRow("adressestruc") = TextBox3.Text
                            MyEditRow("villestruc") = TextBox4.Text
                            MyEditRow("cedexstruc") = TextBox5.Text
                            MyEditRow("telstruc") = TextBox6.Text
                            MyEditRow("faxstruc") = TextBox7.Text
                            MyEditRow("mailstruc") = TextBox8.Text
                            MyEditRow("sitewebstruc") = TextBox9.Text
                            MyEditRow("libtype") = ComboBox1.SelectedItem
     
                            Dim MyCommBuild4 As New MySqlCommandBuilder(Data)
                            Data.Update(Dataset1, strchoix)
     
                            MsgBox("La structure a bien été modifiée", MsgBoxStyle.Information)
                            DataGrid1.Refresh()
    :


    Le code pour la table Structure :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    CREATE TABLE `Structure` (
      `nomstruc` varchar(25) NOT NULL,
      `libstruc` varchar(35) NOT NULL,
      `adressestruc` varchar(35) NOT NULL,
      `villestruc` VARCHAR(20) NOT NULL,
      `cedexstruc` varchar(25) NOT NULL,
      `telstruc` varchar(25) NOT NULL,
      `faxstruc` varchar(25) NOT NULL,
      `mailstruc` varchar(25) NOT NULL,
      `libtype` varchar(25) NOT NULL,
    `sitewebstruc` varchar(30) NOT NULL,
       PRIMARY KEY (`nomstruc`),
       foreign key (`libtype`) references Type(`libtype`) oN DELETE CASCADE ON UPDATE cascade
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    Puisque le reste des fonctions marchent ( ajout, suppression ), Je ne pense pas que la cause soit en dehors de ce bout de code.

    J'ai eu beau chercher, je retrouve souvent le même code, et qui marche chez ces personnes.

    Est-ce les deletes/updates on cascade qui posent problèmes ? :'

    Pour info, lorsque j'édite, le datagrid change, mais pas la base de donnée, du coup, si je rafraichis le datagrid, il m'affichera l'ancienne valeur, toujours présente dans la bdd.

    Je vous serais très reconnaissant de m'aider, de pointer le problème, ou même d'émettre des supositions :p

  2. #2
    Membre très actif
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Septembre 2003
    Messages
    401
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Septembre 2003
    Messages : 401
    Par défaut
    je ne dis pas que je vais avoir la réponse mais c'est quoi ton message d'erreur ?

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Février 2011
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2011
    Messages : 14
    Par défaut
    Il n'y a pas de message d'erreur ...

    Quand j'appuie sur modifier, le datagrid est bien modifié avec les nouvelles valeurs, mais ce n'est pas répercuté sur la BDD :'

  4. #4
    Membre très actif
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Septembre 2003
    Messages
    401
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Septembre 2003
    Messages : 401
    Par défaut
    je tente une idée mais sans vraiment être certain de moi :

    j'ai vu que tu construis ton CommandBuilder juste avant de faire le update.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Dim MyCommBuild4 As New MySqlCommandBuilder(Data)
    Data.Update(Dataset1, strchoix)
    moi j'ai pris l'habitude de le faire dès le début :

    ex:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    Data= New Adapter(SQL, Cnx)
    MyCommBuild4 = New CommandBuilder(Data)
    Dataset1= New DataSet
    Data.Fill(Dataset1)

    Essaye mais j'y crois pas trop.

    par contre je ne comprend pas pourquoi tu fais tout ça

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    Dim MyEditRow As DataRow = Dataset1.Tables(strchoix).Rows(DataGrid1.CurrentRow.Index)
    MyEditRow.BeginEdit()
    MyEditRow("nomstruc") = TextBox1.Text
    MyEditRow("libstruc") = TextBox2.Text
    .......

    Si tu as un formulaire pourquoi n'est il pas rattaché directement via un databinding, idem pour ton datagridview ?

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Février 2011
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2011
    Messages : 14
    Par défaut
    Hum, pour le databinding, je l'utilise pour afficher les infos de la ligne du datagrid sélectionnée quand j'appuie sur modifier, et ça met les infos dans le formulaire.

    Après, je suis étudiant, et j'avoue que je ne sais pas vraiment les diverses options qu'offre le databinding, je sais juste qu'il lie des données à un objet.

    Je me renseigne sur le databinding.

    J'ai essayé ce que tu m'as dit, mais c'est le même problème.

    C'est quand même bizarre que ça marchait avant -_-

  6. #6
    Membre très actif
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Septembre 2003
    Messages
    401
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Septembre 2003
    Messages : 401
    Par défaut
    le databinding te permet de relier une propriété d'un Control sur une source.
    et même de gérer le déplacement dans la source.

    Comme dans ton cas si tu te déplace dans le datagridview cela changera automatiquement les valeurs de ton formulaire.

    Si tu ne connais pas je te conseils ces liens :

    VS2008
    http://msdn.microsoft.com/fr-fr/vbasic/bb265238

    VS2005
    http://msdn.microsoft.com/fr-fr/vbasic/cc507206

    --------------

    Pour ton problème initial essaye ces différents solutions l'une après l'autre

    vérifie que tu envoies bien le bon nom de table dans strchoix.
    attention je sais pas si c'est sensible à la case (majuscule/minuscule)


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Data.Update(Dataset1.Tables(strchoix))
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Data.Update(Dataset1, "Table")

  7. #7
    Membre averti
    Profil pro
    Inscrit en
    Février 2011
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2011
    Messages : 14
    Par défaut
    Merci de m'aider :p

    Voilà pour la première solution :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Data.Update(Dataset1) ', strchoix
    Impossible pour Update de trouver TableMapping['Table'] ou DataTable 'Table'.
    Deuxième :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     Data.Update(Dataset1.tables(strchoix))
    --> aucune erreur, mais modifie juste le datagrid et non la bdd, comme avant

    Troisième :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Data.Update(Dataset1, "personneresp")
    --> pareil que la deuxième

    :'(

  8. #8
    Membre très actif
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Septembre 2003
    Messages
    401
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Septembre 2003
    Messages : 401
    Par défaut
    Met un point d'arret sur la ligne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Data.Update(Dataset1, strchoix)
    et vérifie que dans ton "data" que le MySqlCommandBuilder à bien modifier les propriété updatecommand (ou commandUpdate, je sais plus trop).

    Si oui regarde ce qu'il a mis dans le updatecommande.commandtext
    ça correspond à l'instruction SQL lancé pour un update.

  9. #9
    Membre averti
    Profil pro
    Inscrit en
    Février 2011
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2011
    Messages : 14
    Par défaut
    Hum, apparemment, il y a un select, mais pas d'update ... ( select * from domaine )

    ( j'ai sélectionné un domaine pour l'éditer )

    Comment il peut faire un select en faisant un update :'(

  10. #10
    Membre averti
    Profil pro
    Inscrit en
    Février 2011
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2011
    Messages : 14
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
     Try
     
                Data = New MySqlDataAdapter("SELECT * FROM " & strchoix, hostconn)
                Data.Fill(Dataset1, strchoix)
                DataGrid1.DataSource = Dataset1.Tables(strchoix)
     
            Catch myerror As MySqlException
                MessageBox.Show("Erreur de connection " & myerror.Message)
     
            End Try
    Voilà le code pour remplir le datagrid et créer le data, cela pourrait peut être aider ...

  11. #11
    Membre très actif
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Septembre 2003
    Messages
    401
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Septembre 2003
    Messages : 401
    Par défaut
    il est vrai que l'on a pas vérifier comment tu remplis tes données au départ.

    peux tu nous montrer ton code ?

  12. #12
    Membre averti
    Profil pro
    Inscrit en
    Février 2011
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2011
    Messages : 14
    Par défaut
    Cela risque d'être peu lisible, et surtout bourré d'erreurs ^^ :p ;

    Il y'a surement des variable inutilisées.

    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
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    Imports MySql.Data.MySqlClient
    Imports System.Collections.Generic
    Imports System.ComponentModel
    Imports System.Drawing
    Imports System.Drawing.Printing
     
     
    Public Class Ajout
        Inherits System.Windows.Forms.Form
        Friend WithEvents MyPrintDocument As System.Drawing.Printing.PrintDocument
     
        Dim Data As MySqlDataAdapter ' Création de l'objet pour effectuer des requêtes
     
        Dim Dataset1 As New DataSet ' Création d'un cache qui permet de récupérer des données d'une source
        Dim Choix1 As Choix
        Dim hostconn As New MySqlConnection
        Dim Strch As strchx
        Dim strchoix As String
        Dim exec As MySqlCommand
        Dim exec2 As MySqlCommand
        Dim lire As MySqlDataReader
        Dim suprstr As String
        Dim exec3 As MySqlCommand
        Dim data2 As MySqlDataAdapter
        Dim MyCommBuild As MySqlCommandBuilder
     
        Dim datagridprint As New DataGridViewPrinter.DataGridViewPrinter
     
     
        Private Shared PrintTitle As String = "Listing CIDFF"               ' Header of pages
        Private Shared SelectedColumns As New List(Of String)  ' The Columns Selected by user to print.
        Private Shared AvailableColumns As New List(Of String) ' All Columns avaiable in DataGridView   
        Private Shared SelectedRows As New List(Of Integer) ' All Columns avaiable in DataGridView
     
     
        Public Sub Ajout_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            hostconn.Close()
            hostconn.ConnectionString = "server=localhost;" _
             & "user id=root;" _
             & "password=;" _
             & "database=cidff"
            hostconn.Open()
            With DataGrid1
                ' 
                .SelectionMode = DataGridViewSelectionMode.FullRowSelect
     
                .MultiSelect = False
     
     
                ' DataGrid1.ColumnCount = 9
                ' DataGrid1.AutoGenerateColumns = False
     
                '.Dock = DockStyle.Fill 
                .RowHeadersVisible = False
     
     
            End With
     
     
            If Form1.CBajout.SelectedItem = "Personne" Then
                Strch = strchx.Personne
                Label1.Text = "Nom"
                Label2.Text = "Prénom"
                Label3.Text = "Fonction"
                Label4.Text = "Mail"
                Label5.Text = "Adresse"
                Label6.Text = "Ville"
                Label7.Text = "Cedex"
                Label8.Text = "Tel Portable"
                Label9.Text = "Tel Fixe"
                TextBox10.Visible = False
                Label12.Visible = False
                Try
                    exec = New MySqlCommand("SELECT Nomstruc from Structure", hostconn)
                    lire = exec.ExecuteReader
                    Do While lire.Read()
                        ComboBox1.Items.Add(lire("Nomstruc"))
                    Loop
                    lire.Close()
                Catch ex As Exception
                    MessageBox.Show(ex.ToString(), "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End Try
     
     
            ElseIf Form1.CBajout.SelectedItem = "Projet" Then
     
                Strch = strchx.Projet
                Label3.Visible = False
                Label4.Visible = False
                Label5.Visible = False
                Label6.Visible = False
                Label7.Visible = False
                Label8.Visible = False
                Label9.Visible = False
                Label10.Visible = False
                Label12.Visible = False
     
                TextBox3.Visible = False
                TextBox4.Visible = False
                TextBox5.Visible = False
                TextBox6.Visible = False
                TextBox7.Visible = False
                TextBox8.Visible = False
                TextBox9.Visible = False
                TextBox10.Visible = False
     
                ComboBox1.Visible = False
                Label1.Text = "Nom du projet"
                Label2.Text = "Libellé"
     
     
     
            ElseIf Form1.CBajout.SelectedItem = "Structure" Then
                Strch = strchx.Struc
                Label1.Text = "Nom"
                Label2.Text = "Libellé"
                Label3.Text = "Adresse"
                Label4.Text = "Ville"
                Label5.Text = "Cedex"
                Label6.Text = "Téléphone"
                Label7.Text = "Fax"
                Label8.Text = "Email"
                Label9.Text = "Site web"
     
                Label10.Text = "Type de structure "
     
                TextBox10.Visible = False
     
     
                Try
                    exec = New MySqlCommand("SELECT libtype from type", hostconn)
                    lire = exec.ExecuteReader
                    Do While lire.Read()
                        ComboBox1.Items.Add(lire("Libtype"))
                    Loop
                    lire.Close()
                Catch ex As Exception
                    MessageBox.Show(ex.ToString(), "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End Try
     
            ElseIf Form1.CBajout.SelectedItem = "Domaine" Then
     
                Strch = strchx.domaine
                Label3.Visible = False
                Label4.Visible = False
                Label5.Visible = False
                Label6.Visible = False
                Label7.Visible = False
                Label8.Visible = False
                Label9.Visible = False
                Label10.Visible = False
                Label12.Visible = False
     
                TextBox2.Visible = False
                TextBox3.Visible = False
                TextBox4.Visible = False
                TextBox5.Visible = False
                TextBox6.Visible = False
                TextBox7.Visible = False
                TextBox8.Visible = False
                TextBox9.Visible = False
                TextBox10.Visible = False
     
                ComboBox1.Visible = False
                Label1.Text = "Libellé du Domaine"
     
            ElseIf Form1.CBajout.SelectedItem = "Responsable" Then
                Strch = strchx.responsable
                Label1.Text = "Nom"
                Label2.Text = "Prénom"
                Label3.Text = "Fonction"
                Label4.Text = "Mail"
                Label5.Text = "Adresse"
                Label6.Text = "Ville"
                Label7.Text = "Cedex"
                Label8.Text = "Tel Portable"
                Label9.Text = "Tel Fixe"
                ComboBox1.Visible = False
                Label12.Visible = False
                TextBox10.Visible = False
            ElseIf Form1.CBajout.SelectedItem = "Type" Then
     
                Strch = strchx.type
                Label2.Visible = False
                Label3.Visible = False
                Label4.Visible = False
                Label5.Visible = False
                Label6.Visible = False
                Label7.Visible = False
                Label8.Visible = False
                Label9.Visible = False
                Label10.Visible = False
                Label11.Visible = False
                Label12.Visible = False
                Btajlien.Enabled = False
                TextBox2.Visible = False
                TextBox3.Visible = False
                TextBox4.Visible = False
                TextBox5.Visible = False
                TextBox6.Visible = False
                TextBox7.Visible = False
                TextBox8.Visible = False
                TextBox9.Visible = False
                TextBox10.Visible = False
     
                ComboBox1.Visible = False
                Label1.Text = "Libellé du Type"
     
            End If
     
            strchoix = Form1.CBajout.SelectedItem
     
            If Form1.CBajout.SelectedItem = "Responsable" Then
                strchoix = "personneresp"
            End If
     
     
     
            Choix1 = Choix.Choixdef
     
            Try
     
                Data = New MySqlDataAdapter("SELECT * FROM " & strchoix, hostconn)
                Data.Fill(Dataset1, strchoix)
                DataGrid1.DataSource = Dataset1.Tables(strchoix)
     
            Catch myerror As MySqlException
                MessageBox.Show("Erreur de connection " & myerror.Message)
     
            End Try
     
            ' à faire : Ajouter cette personne à telle entreprise + fait
            ' Ajouter un projet à telle entreprise 
            ' comment faire pour ajouter plusieurs responsables à une personne, ou plusieurs projets à une entreprise 
     
     
     
     
     
     
     
            Call RemoveDataBindings() ' Efface les databindings qui viennent d'être utilisés
        End Sub
     
     
        Private Enum Choix
            Choixdef = 0
            ChoixAj = 1
            ChoixEdit = 2
            choixSupr = 3
        End Enum
     
        Private Enum strchx
            Personne = 0
            Projet = 1
            Struc = 2
            domaine = 3
            type = 4
            responsable = 5
        End Enum
     
        Private Sub Btajchoixaj_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btajoutaj.Click
     
            Choix1 = Choix.ChoixAj
     
        End Sub
     
        Private Sub btajmodifaj_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btajmodifaj.Click
     
            Choix1 = Choix.ChoixEdit
            Select Case Strch
                Case Is = strchx.Personne
     
                    Me.BindingContext(Dataset1.Tables(strchoix)).Position = DataGrid1.CurrentRow.Index
                    TextBox1.DataBindings.Add("text", Dataset1.Tables(strchoix), "nompers")
                    TextBox2.DataBindings.Add("text", Dataset1.Tables(strchoix), "prenompers")
                    TextBox3.DataBindings.Add("text", Dataset1.Tables(strchoix), "fonctionpers")
                    TextBox4.DataBindings.Add("text", Dataset1.Tables(strchoix), "mailpers")
                    TextBox5.DataBindings.Add("text", Dataset1.Tables(strchoix), "adresse")
                    TextBox6.DataBindings.Add("text", Dataset1.Tables(strchoix), "villepers")
                    TextBox7.DataBindings.Add("text", Dataset1.Tables(strchoix), "cedexpers")
                    TextBox8.DataBindings.Add("text", Dataset1.Tables(strchoix), "telfixepers")
                    TextBox9.DataBindings.Add("text", Dataset1.Tables(strchoix), "telportpers")
                    TextBox20.DataBindings.Add("text", Dataset1.Tables(strchoix), "numpers")
     
                Case Is = strchx.Projet
     
                    TextBox1.DataBindings.Add("text", Dataset1.Tables(strchoix), "nomproj")
                    TextBox2.DataBindings.Add("text", Dataset1.Tables(strchoix), "libproj")
     
                Case Is = strchx.Struc
     
                    TextBox1.DataBindings.Add("text", Dataset1.Tables(strchoix), "nomstruc")
                    TextBox2.DataBindings.Add("text", Dataset1.Tables(strchoix), "libstruc")
                    TextBox3.DataBindings.Add("text", Dataset1.Tables(strchoix), "adressestruc")
                    TextBox4.DataBindings.Add("text", Dataset1.Tables(strchoix), "villestruc")
                    TextBox5.DataBindings.Add("text", Dataset1.Tables(strchoix), "cedexstruc")
                    TextBox6.DataBindings.Add("text", Dataset1.Tables(strchoix), "telstruc")
                    TextBox7.DataBindings.Add("text", Dataset1.Tables(strchoix), "faxstruc")
                    TextBox8.DataBindings.Add("text", Dataset1.Tables(strchoix), "mailstruc")
                    TextBox9.DataBindings.Add("text", Dataset1.Tables(strchoix), "sitewebstruc")
     
                Case Is = strchx.domaine
     
                    TextBox1.DataBindings.Add("text", Dataset1.Tables(strchoix), "libdomaine")
     
                Case Is = strchx.responsable
     
                    TextBox1.DataBindings.Add("text", Dataset1.Tables(strchoix), "nomresp")
                    TextBox2.DataBindings.Add("text", Dataset1.Tables(strchoix), "prenomresp")
                    TextBox3.DataBindings.Add("text", Dataset1.Tables(strchoix), "fonctionresp")
                    TextBox4.DataBindings.Add("text", Dataset1.Tables(strchoix), "mailresp")
                    TextBox5.DataBindings.Add("text", Dataset1.Tables(strchoix), "adresseresp")
                    TextBox6.DataBindings.Add("text", Dataset1.Tables(strchoix), "villeresp")
                    TextBox7.DataBindings.Add("text", Dataset1.Tables(strchoix), "cedexresp")
                    TextBox8.DataBindings.Add("text", Dataset1.Tables(strchoix), "telfixeresp")
                    TextBox9.DataBindings.Add("text", Dataset1.Tables(strchoix), "telportresp")
     
                Case Is = strchx.type
     
                    TextBox1.DataBindings.Add("text", Dataset1.Tables(strchoix), "libtype")
     
            End Select
     
            Call RemoveDataBindings()
     
        End Sub
        Private Sub RemoveDataBindings()
            Dim Ctrl As Control
            For Each Ctrl In GroupBox2.Controls
                Ctrl.DataBindings.Clear()
            Next Ctrl
            popupmailing.RichTextBox1.DataBindings.Clear()
        End Sub
     
     
        Private Sub Btajvalid_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btajvalid.Click
     
     
     
     
            Select Case Choix1
                Case Is = Choix.ChoixEdit
                    Select Case Strch
                        Case Is = strchx.Personne
                            Me.BindingContext(Dataset1.Tables(strchoix)).Position = DataGrid1.CurrentRow.Index
     
     
                            Dim MyEditRow As DataRow = Dataset1.Tables(strchoix).Rows(DataGrid1.CurrentRow.Index)
     
                            MyEditRow.BeginEdit()
                            MyEditRow("nompers") = TextBox1.Text
                            MyEditRow("prenompers") = TextBox2.Text
                            MyEditRow("fonctionpers") = TextBox3.Text
                            MyEditRow("mailpers") = TextBox4.Text
                            MyEditRow("adressepers") = TextBox5.Text
                            MyEditRow("villepers") = TextBox6.Text
                            MyEditRow("cedexpers") = TextBox7.Text
                            MyEditRow("telportpers") = TextBox8.Text
                            MyEditRow("telfixepers") = TextBox9.Text
     
                            MyEditRow("nomstruc") = ComboBox1.SelectedItem
     
     
                            Dim MyCommBuild As New MySqlCommandBuilder(Data)
                            Data.Update(Dataset1, strchoix)
                            DataGrid1.Refresh()
     
                            MsgBox("La personne a bien été modifiée", MsgBoxStyle.Information)
     
                            DataGrid1.Refresh()
     
                        Case Is = strchx.Projet
                            Dim MyEditRow As DataRow = Dataset1.Tables(strchoix).Rows(DataGrid1.CurrentRow.Index)
     
                            MyEditRow.BeginEdit()
                            MyEditRow("nomproj") = TextBox1.Text
                            MyEditRow("libproj") = TextBox2.Text
     
                            Dim MyCommBuild As New MySqlCommandBuilder(Data)
                            Data.Update(Dataset1, strchoix)
     
                            MsgBox("Le projet a bien été modifié", MsgBoxStyle.Information)
     
                            DataGrid1.Refresh()
     
                        Case Is = strchx.Struc
     
     
     
                            Dim MyEditRow As DataRow = Dataset1.Tables(strchoix).Rows(DataGrid1.CurrentRow.Index)
                            MyEditRow.BeginEdit()
                            MyEditRow("nomstruc") = TextBox1.Text
                            MyEditRow("libstruc") = TextBox2.Text
                            MyEditRow("adressestruc") = TextBox3.Text
                            MyEditRow("villestruc") = TextBox4.Text
                            MyEditRow("cedexstruc") = TextBox5.Text
                            MyEditRow("telstruc") = TextBox6.Text
                            MyEditRow("faxstruc") = TextBox7.Text
                            MyEditRow("mailstruc") = TextBox8.Text
                            MyEditRow("sitewebstruc") = TextBox9.Text
                            MyEditRow("libtype") = ComboBox1.SelectedItem
     
     
                            Data.Update(Dataset1, strchoix)
     
                            MsgBox("La structure a bien été modifiée", MsgBoxStyle.Information)
                            DataGrid1.Refresh()
     
                        Case Is = strchx.domaine
     
                            Dim MyEditRow As DataRow = Dataset1.Tables(strchoix).Rows(DataGrid1.CurrentRow.Index)
     
                            MyEditRow.BeginEdit()
                            MyEditRow("libdomaine") = TextBox1.Text
     
                            Dim MyCommBuild As New MySqlCommandBuilder(Data)
                            Data.Update(Dataset1, strchoix)
     
                            MsgBox("Le domaine a bien été modifié", MsgBoxStyle.Information)
     
                            DataGrid1.Refresh()
     
                        Case Is = strchx.type
     
                            Dim MyEditRow As DataRow = Dataset1.Tables(strchoix).Rows(DataGrid1.CurrentRow.Index)
     
                            MyEditRow.BeginEdit()
                            MyEditRow("libtype") = TextBox2.Text
     
                            Dim MyCommBuild As New MySqlCommandBuilder(Data)
                            Data.Update(Dataset1, strchoix)
     
                            MsgBox("Le type a bien été modifié", MsgBoxStyle.Information)
     
                            DataGrid1.Refresh()
     
                        Case Is = strchx.responsable
     
                            Me.BindingContext(Dataset1.Tables(strchoix)).Position = DataGrid1.CurrentRow.Index
     
     
                            Dim MyEditRow As DataRow = Dataset1.Tables(strchoix).Rows(DataGrid1.CurrentRow.Index)
     
                            MyEditRow.BeginEdit()
                            MyEditRow("nomresp") = TextBox1.Text
                            MyEditRow("prenomresp") = TextBox2.Text
                            MyEditRow("fonctionresp") = TextBox3.Text
                            MyEditRow("mailresp") = TextBox4.Text
                            MyEditRow("adresseresp") = TextBox5.Text
                            MyEditRow("villeresp") = TextBox6.Text
                            MyEditRow("cedexresp") = TextBox7.Text
                            MyEditRow("telportresp") = TextBox8.Text
                            MyEditRow("telfixeresp") = TextBox9.Text
     
     
     
                            Dim MyCommBuildx As New MySqlCommandBuilder(Data)
                            Data.Update(Dataset1, "personneresp")
                            DataGrid1.Refresh()
     
                            MsgBox("Le Responsable a bien été modifiée", MsgBoxStyle.Information)
     
                            DataGrid1.Refresh()
     
                    End Select
                Case Is = Choix.ChoixAj
                    Select Case Strch
                        Case Is = strchx.Personne
                            Dim MyNewRow As DataRow = Dataset1.Tables(strchoix).NewRow
     
                            MyNewRow("nompers") = TextBox1.Text
                            MyNewRow("prenompers") = TextBox2.Text
                            MyNewRow("fonctionpers") = TextBox3.Text
                            MyNewRow("mailpers") = TextBox4.Text
                            MyNewRow("adressepers") = TextBox5.Text
                            MyNewRow("villepers") = TextBox6.Text
                            MyNewRow("cedexpers") = TextBox7.Text
                            MyNewRow("telportpers") = TextBox8.Text
                            MyNewRow("telfixepers") = TextBox9.Text
                            MyNewRow("nomstruc") = ComboBox1.SelectedItem
     
     
                            Dataset1.Tables(strchoix).Rows.Add(MyNewRow)
     
                            Dim MyCommBuild5 As New MySqlCommandBuilder(Data)
                            Data.Update(Dataset1, strchoix)
                        Case Is = strchx.Projet
     
                            Dim MyNewRow As DataRow = Dataset1.Tables(strchoix).NewRow
     
                            MyNewRow("Nomproj") = TextBox1.Text
                            MyNewRow("Libproj") = TextBox2.Text
     
                            Dataset1.Tables(strchoix).Rows.Add(MyNewRow)
     
                            Dim MyCommBuild6 As New MySqlCommandBuilder(Data)
                            Data.Update(Dataset1, strchoix)
     
     
     
                            'Dim instr As String
     
                            'Data.Update(Dataset1, Strchoix)
     
     
                            'instr = "insert into persresppers(nomresp,numpers) values(" & ComboBox3.SelectedItem & ", " & TextBox20.Text & ")"
                            'instr = "INSERT INTO persresppers (nomresp, numpers) " & _
                            '"VALUES (" & ComboBox3.SelectedItem
                            'instr = instr + ", " & TextBox20.Text
                            'instr = instr + " )"
     
                            'exec3 = New MySqlCommand
                            'data3 = New MySqlDataAdapter
                            'exec3.CommandText = instr
                            'data3.InsertCommand = exec3
                            'data3.InsertCommand.Connection = hostconn
     
                            'data3.InsertCommand.ExecuteNonQuery()
     
     
                            ' mettre un try catch pour dire s'il est déjà lier à la personne
     
                            'Dim strnum As String
                            'Dim execnum As MySqlCommand
                            'Dim datanum As MySqlDataAdapter
     
                            'execnum = New MySqlCommand
                            'datanum = New MySqlDataAdapter
                            'execnum.CommandText = "select numpers from personne where nompers = '" & TextBox1.Text & "'"
                            'datanum.SelectCommand = execnum
                            'datanum.SelectCommand.Connection = hostconn
                            ''strnum = datanum.SelectCommand.ExecuteReader
     
                            'MessageBox.Show(strnum)
     
     
     
                            'exec3 = New MySqlCommand
                            'data3 = New MySqlDataAdapter
                            'exec3.CommandText = "INSERT INTO `cidff`.`persresppers` (`nomresp`, `numpers`) VALUES ('" & ComboBox3.SelectedItem & "', '" & strnum & "')"
                            ''exec3.Parameters.Add("nomresp", ComboBox3.SelectedItem)
                            ''exec3.Parameters.Add("numpers", TextBox20.Text)
                            'data3.InsertCommand = exec3
                            'data3.InsertCommand.Connection = hostconn
     
                            'data3.InsertCommand.ExecuteNonQuery()
                            'Data.Update(Dataset1, Strchoix)
                        Case Is = strchx.Struc
     
                            Dim MyNewRow As DataRow = Dataset1.Tables(strchoix).NewRow
     
                            MyNewRow("nomstruc") = TextBox1.Text
                            MyNewRow("libstruc") = TextBox2.Text
                            MyNewRow("adressestruc") = TextBox3.Text
                            MyNewRow("villestruc") = TextBox4.Text
                            MyNewRow("cedexstruc") = TextBox5.Text
                            MyNewRow("telstruc") = TextBox6.Text
                            MyNewRow("faxstruc") = TextBox7.Text
                            MyNewRow("mailstruc") = TextBox8.Text
                            MyNewRow("sitewebstruc") = TextBox9.Text
                            MyNewRow("libtype") = ComboBox1.SelectedItem
     
                            Dataset1.Tables(strchoix).Rows.Add(MyNewRow)
     
                            Dim MyCommBuild7 As New MySqlCommandBuilder(Data)
                            Data.Update(Dataset1, strchoix)
     
                        Case Is = strchx.domaine
     
                            Dim MyNewRow As DataRow = Dataset1.Tables(strchoix).NewRow
     
                            MyNewRow("libdomaine") = TextBox1.Text
     
                            Dataset1.Tables(strchoix).Rows.Add(MyNewRow)
     
                            Dim MyCommBuild5 As New MySqlCommandBuilder(Data)
                            Data.Update(Dataset1, strchoix)
     
                        Case Is = strchx.type
     
                            Dim MyNewRow As DataRow = Dataset1.Tables(strchoix).NewRow
     
                            MyNewRow("libtype") = TextBox1.Text
                            Dataset1.Tables(strchoix).Rows.Add(MyNewRow)
     
                            Dim MyCommBuild5 As New MySqlCommandBuilder(Data)
                            Data.Update(Dataset1, strchoix)
     
                        Case Is = strchx.responsable
     
                            Dim MyNewRow As DataRow = Dataset1.Tables(strchoix).NewRow
     
                            MyNewRow("nomresp") = TextBox1.Text
                            MyNewRow("prenomresp") = TextBox2.Text
                            MyNewRow("fonctionresp") = TextBox3.Text
                            MyNewRow("mailresp") = TextBox4.Text
                            MyNewRow("adresseresp") = TextBox5.Text
                            MyNewRow("villeresp") = TextBox6.Text
                            MyNewRow("cedexresp") = TextBox7.Text
                            MyNewRow("telportresp") = TextBox8.Text
                            MyNewRow("telfixeresp") = TextBox9.Text
     
     
                            Dataset1.Tables(strchoix).Rows.Add(MyNewRow)
     
                            Dim MyCommBuild5 As New MySqlCommandBuilder(Data)
                            Data.Update(Dataset1, strchoix)
     
                    End Select
     
                Case Is = Choix.choixSupr
                    DataGrid1.Refresh()
     
                    Dataset1.Tables(strchoix).Rows(DataGrid1.CurrentRow.Index).Delete() ' Efface la ligne selectionnée
                    Dim MyCommBuild As New MySqlCommandBuilder(Data)
                    Data.Update(Dataset1, strchoix)
     
            End Select
     
     
            Data.Update(Dataset1, strchoix)
     
     
     
     
            RemoveDataBindings()
     
            'Try ' Effectue un essai, et envoie une valeur lors d'une erreur
     
            '    Data = New MySqlDataAdapter("SELECT * FROM " & strchoix, hostconn) ' Requête vers la base de données
            '    Data.Fill(Dataset1, strchoix)
            '    DataGrid1.DataSource = Dataset1.Tables(strchoix) 'Permet de donner les données au datagrid
     
            'Catch myerror As MySqlException
            '    MessageBox.Show("Erreur de connection " & myerror.Message) ' Message affiché lors d'une erreur de connection
     
            'End Try
     
     
        End Sub
     
        Private Sub Btajretour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btajretour.Click
            hostconn.Close()
            hostconn.Dispose()
            Me.DataGrid1.DataSource = Nothing ' Ne marche pas ?
            Me.DataGrid1.Rows.Clear() 'Same
            Me.Close()
            Me.Dispose()
        End Sub
     
        Private Sub Btajsuprr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btajsuprr.Click
            Choix1 = Choix.choixSupr
     
        End Sub
     
        Private Sub Btajlien_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btajlien.Click
            FormAjoutlien.Show()
        End Sub
     
        Private Sub MenuStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MenuStrip1.ItemClicked
     
        End Sub
     
     
        Private Sub ImprimerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImprimerToolStripMenuItem.Click
     
     
     
     
            If datagridprint.SetupThePrinting(DataGrid1, Me.Text) Then
                Dim MyPrintPreviewDialog As New PrintPreviewDialog()
                MyPrintPreviewDialog.Document = PrintDocument1
                MyPrintPreviewDialog.ShowDialog()
            End If
        End Sub
     
        Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
            Dim more As Boolean = datagridprint.DrawDataGridView(e.Graphics)
            If more = True Then
                e.HasMorePages = True
            End If
        End Sub
     
     
        Private Sub MailingToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MailingToolStripMenuItem.Click
            Dim i, j As Integer
            Dim test, mailch As String
            i = DataGrid1.Rows.Count - 2
            j = 0
            test = ""
     
            If Form1.CBajout.SelectedItem = "Personne" Then
                mailch = "mailpers"
            ElseIf Form1.CBajout.SelectedItem = "Responsable" Then
                mailch = "mailresp"
            ElseIf Form1.CBajout.SelectedItem = "Structure" Then
                mailch = "mailstruc"
            End If
     
            If Form1.CBajout.SelectedItem = "Personne" Or Form1.CBajout.SelectedItem = "Responsable" Or Form1.CBajout.SelectedItem = "Structure" Then
     
                For j = 0 To i Step 1
     
                    test = test + DataGrid1.Rows(j).Cells(mailch).Value.ToString + ", "
     
                Next
                popupmailing.RichTextBox1.Text = test
                popupmailing.RichTextBox1.Focus()
                popupmailing.RichTextBox1.SelectionStart = 0
                popupmailing.RichTextBox1.SelectionLength = Len(popupmailing.RichTextBox1.Text)
                popupmailing.ShowDialog()
     
            Else
                MessageBox.Show("Fonction non disponible sur les éléments sélectionnés")
            End If
     
     
     
        End Sub
    End Class

  13. #13
    Membre très actif
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Septembre 2003
    Messages
    401
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Septembre 2003
    Messages : 401
    Par défaut
    (désolé j'ai écrit à la chaine sans relire )
    Le prend pas mal mais effectivement il y a beaucoup à dire, c'est normal c'est le début !

    Un point facteur d'erreur.

    tu déclares en haut de ton code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
      Dim MyCommBuild As MySqlCommandBuilder
    donc déclaration global, visibilité global à ta fenêtre.
    sauf que après dans ton code tu fais :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Dim MyCommBuild As New MySqlCommandBuilder(Data)
    Attention, en faisant cela tu perds la visibilité et surtout cette variable devient local, c'est à dire qu'en sortant de ton code ton MyCommBuild est vide !

    Si tu veux une vision global tu aurais dû écrire
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    MyCommBuild = New MySqlCommandBuilder(Data)
    Là tu instancies ton objet MyCommBuild qui est déclaré en global
    et en sortant du code ton MyCommBuild reste vivant !

    --------------
    Ensuite ton principe de formulaire générique en soit et une bonne idée par contre je pense (et ce n'est que mon avis) que ta façon de faire te fait perdre en clarté, en temps, en soupless.

    Connais-tu les UserControl ?
    une sorte de form sans cadre que tu peux coller dans une form
    Ensuite selon les choix de ton user, tu affiche le usercontrol de ton choix.
    En rendu visuel tu auras la même chose.
    1- ton code sera propre pour chaque formulaire
    2- si tu as un changement important sur un des formulaires ça t'évite de pleurer !
    3- ça t'evite le code de maquer et changement de nom des label et autre binding
    4- ça te permet dessiner tes formulaires proprement et de faire des bindings avec les assistants visual studio et sans erreur.
    5- etc....


    Exemple de chargement de usercontrol
    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
    Public Class Form1
     
        Private UC_Projet As New UserControl_projet With {.Dock = DockStyle.Fill, .Visible = True}
        Private UC_Personne As New UserControl_Personne With {.Dock = DockStyle.Fill, .Visible = True}
        Private UC_Depart As New UserControl_depart With {.Dock = DockStyle.Fill, .Visible = True}
     
     
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     'Panel1 est un objet panel posé sur la form
     
            Select Case Form1.CBajout.SelectedItem
     
                Case "Personne"
                    Panel1.Controls.Clear()
                    Panel1.Controls.Add(UC_Personne)
     
                Case "projet"
                    Panel1.Controls.Clear()
                    Panel1.Controls.Add(UC_Projet)
     
     
                Case Else
                    Panel1.Controls.Clear()
                    Panel1.Controls.Add(UserControl_depart)
     
            End Select
     
        End Sub
    End Class

  14. #14
    Membre averti
    Profil pro
    Inscrit en
    Février 2011
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2011
    Messages : 14
    Par défaut
    Merci beaucoup de prendre de ton temps pour m'aider !

    Pour les usercontrol, ça semble effectivement 40 fois plus simple que ce que j'ai fais, et maintenant que tu les les à fais connaître, je vais les utiliser :p

    Pour la mycommbuild, effectivement, c'est une erreur grotesque que j'ai faite en le déclarant dans la fonction

    Voilà ce que ça donne donc

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     Case Is = strchx.domaine
     
                            Dim MyEditRow As DataRow = Dataset1.Tables(strchoix).Rows(DataGrid1.CurrentRow.Index)
     
                            MyEditRow.BeginEdit()
                            MyEditRow("libdomaine") = TextBox1.Text
     
                            MyCommBuild = New MySqlCommandBuilder(Data)
                            Data.Update(Dataset1, strchoix)
     
                            MsgBox("Le domaine a bien été modifié", MsgBoxStyle.Information)
     
                            DataGrid1.Refresh()
    Il me fait la même chose qu'avant, il change le datagrid, mais pas la bdd, et il semble toujours avec une select dans le data.update :'(

  15. #15
    Membre très actif
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Septembre 2003
    Messages
    401
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Septembre 2003
    Messages : 401
    Par défaut
    Je n'ai jamais utilisé cette forme
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    Dim MyEditRow As DataRow = Dataset1.Tables(strchoix).Rows(DataGrid1.CurrentRow.Index)
    MyEditRow.BeginEdit()
    mais par contre ne faudrait il pas un
    pour que la modif se répercute dans ta datarow ?

    ce qui donnerai un truc du genre

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    MyEditRow.BeginEdit()
    MyEditRow("libdomaine") = TextBox1.Text
    MyEditRow.EndEdit
    MyCommBuild = New MySqlCommandBuilder(Data)
    Data.Update(Dataset1, strchoix)
    pense à regarder ces liens,

    dit toi que le temps que tu perds à faire les exercices, tu vas le gagner*10 par la suite.

    VS2008
    http://msdn.microsoft.com/fr-fr/vbasic/bb265238

    VS2005
    http://msdn.microsoft.com/fr-fr/vbasic/cc507206

  16. #16
    Membre averti
    Profil pro
    Inscrit en
    Février 2011
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2011
    Messages : 14
    Par défaut
    Merci beaucoup, c'était ça !

    Un truc vraiment bête, je dois avouer :'

    Mais j'ai l'impression que c'est souvent comme ça :p

    Merci énormément pour ton aide, tu m'as fait apprendre plusieurs choses utiles et plus de m'avoir aidé et trouver la solution.

    Je vais regarder ton lien sur VS 2008, merci :p

  17. #17
    Membre très actif
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Septembre 2003
    Messages
    401
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Septembre 2003
    Messages : 401
    Par défaut
    Dit toi souvent que si il y a un beginXXX, il y a de forte de chance pour d'avoir un EndXXX

    On a tous débuté un jour et un reçu un coup de main d'un forum, faut juste ne pas l'oublier et faire suivre la chaîne de l'entraide.
    c'est beau j'vais me faire pleurer, lol

    bon courage, @+

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [WD-2000] Problème pour éditer des étiquettes
    Par juju05 dans le forum Word
    Réponses: 5
    Dernier message: 09/02/2014, 20h23
  2. [2008R2] SSMS : problème pour éditer un step dans un job
    Par Kropernic dans le forum Administration
    Réponses: 2
    Dernier message: 04/07/2013, 12h47
  3. Problème pour remplir mon datagridview
    Par jacko842 dans le forum VB.NET
    Réponses: 4
    Dernier message: 25/03/2010, 17h14
  4. Réponses: 4
    Dernier message: 04/05/2007, 12h58
  5. Réponses: 21
    Dernier message: 26/04/2007, 16h49

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo