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

C# Discussion :

problème sur la modification des données d'un champ


Sujet :

C#

  1. #1
    Débutant  
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    1 571
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 1 571
    Points : 353
    Points
    353
    Par défaut problème sur la modification des données d'un champ
    Bonjour tout le monde,

    Voila, j'ai une application sous VisualStudio.Net2003 et une base de données SqlServer2000.

    Dans cette application, j'ai des renseignements sur le clients, le contact et la machine....

    Imaginon que le client, le contact mais aussi la machine existe déja dans la base SqlServer 2000. Je voudrais que l'utilisateur de cette application puisse modifier la configuration de la machine et qu'en appuyant sur un bouton cela enregistre la modification effectuées sur la configuration de la machine.

    EXEMPLE : configMachine = 5Go. L'utilisateur change '5Go' en '15Go'. Je souhaiterais que dans la base au lieu d'avoir 5 on a 15 Go après avoir cliqué sur le bouton.

    J'ai commencé a faire comme cela mais je souhaiterais avoir vos conseil et votre aide :
    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
    				SqlDataAdapter _MonDataAdapter3;
    				System.Data.DataTable _MaDataTable3;
     
    				// RECUPERER La configMat
    				string RequeteSQL3 = "SELECT M_CONFMAT FROM MACHINE WHERE M_CONFMAT='" + ConfigMachine.Text + "'";
     
    				_MonDataAdapter3 = new SqlDataAdapter(RequeteSQL3, connection);
     
    				_MaDataTable3 = new DataTable();
    				_MonDataAdapter3.Fill(_MaDataTable3);
     
    else if (_MaDataTable3.Rows.Count > 0) and (ConfigMachine!=M_CONFMAT)
    				{
     
    				}
    Auriez-vous fait comme cela??
    1) Si non, comment feriez vous??
    2) Si oui, dans le code suivant je me demande si la syntaxe se fait comme cela??
    :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    else if (_MaDataTable3.Rows.Count > 0) and (ConfigMachine!=M_CONFMAT)
    merci d'avance

  2. #2
    Expert éminent sénior
    Avatar de Skyounet
    Homme Profil pro
    Software Engineer
    Inscrit en
    Mars 2005
    Messages
    6 380
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Software Engineer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 6 380
    Points : 13 380
    Points
    13 380
    Par défaut
    Oulala c'est bien bizarre comme code.

    Donc si j'ai bien compris c'est en mode déconnecté c'est ça ?

    Dans tu modifies ta DataTable et après tu fais un Update de ton Adapter.
    http://msdn2.microsoft.com/fr-fr/lib...33(VS.80).aspx
    Introduction à Silverlight 4 (new) ; Localisation d'une application Silverlight (new) ;
    Mon espace perso[/B]

    La connaissance s’acquiert par l’expérience, tout le reste n’est que de l’information. Albert Einstein[/SIZE]

  3. #3
    Débutant  
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    1 571
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 1 571
    Points : 353
    Points
    353
    Par défaut réponse à Skyrunner
    Qu'appelle tu en mode déconnectée??

    Je vois pas trop comment utiliser le code suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    try
    {
        this.Validate();
        this.customersBindingSource.EndEdit();
        this.customersTableAdapter.Update(this.northwindDataSet.Customers);
        MessageBox.Show("Update successful");
    }
    catch (System.Exception ex)
    {
        MessageBox.Show("Update failed");
    }
    merci d'avance!!

  4. #4
    Membre confirmé
    Profil pro
    Développeur freelance
    Inscrit en
    Août 2006
    Messages
    453
    Détails du profil
    Informations personnelles :
    Localisation : France, Ardèche (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur freelance

    Informations forums :
    Inscription : Août 2006
    Messages : 453
    Points : 586
    Points
    586
    Par défaut
    Citation Envoyé par loic20h28 Voir le message
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    else if (_MaDataTable3.Rows.Count > 0) and (ConfigMachine!=M_CONFMAT)
    Je ne sais pas ce que vaut "M_CONFMAT", mais si c'est un string alors ce sera plutôt
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    else if (_MaDataTable3.Rows.Count > 0) and (ConfigMachine.Text != M_CONFMAT)
    Mosco

  5. #5
    Débutant  
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    1 571
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 1 571
    Points : 353
    Points
    353
    Par défaut réponse à MoscoBlade
    "M_CONFMAT" est le nom du champ correspondant a la configuration de la machine dans la base.


    merci d'avance!!

  6. #6
    Expert éminent sénior
    Avatar de Skyounet
    Homme Profil pro
    Software Engineer
    Inscrit en
    Mars 2005
    Messages
    6 380
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Software Engineer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 6 380
    Points : 13 380
    Points
    13 380
    Par défaut
    Euh tu utilises des Dataset/Datatable ou tu fais tu es en mode connecté (DataReader et compagnie ?).
    Introduction à Silverlight 4 (new) ; Localisation d'une application Silverlight (new) ;
    Mon espace perso[/B]

    La connaissance s’acquiert par l’expérience, tout le reste n’est que de l’information. Albert Einstein[/SIZE]

  7. #7
    Débutant  
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    1 571
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 1 571
    Points : 353
    Points
    353
    Par défaut réponse à Skyrunner
    Ben pour la modification, je fais comme j'ai mit la haut.

    merci d'avance!!

  8. #8
    Expert éminent sénior
    Avatar de Skyounet
    Homme Profil pro
    Software Engineer
    Inscrit en
    Mars 2005
    Messages
    6 380
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Software Engineer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 6 380
    Points : 13 380
    Points
    13 380
    Par défaut
    Citation Envoyé par loic20h28 Voir le message
    Ben pour la modification, je fais comme j'ai mit la haut.

    merci d'avance!!
    Oui mais pour aller chercher les données comment fais-tu ?
    Introduction à Silverlight 4 (new) ; Localisation d'une application Silverlight (new) ;
    Mon espace perso[/B]

    La connaissance s’acquiert par l’expérience, tout le reste n’est que de l’information. Albert Einstein[/SIZE]

  9. #9
    Débutant  
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    1 571
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 1 571
    Points : 353
    Points
    353
    Par défaut réponse à Skyrunner
    Ben c'est pas ça??

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    /*	SqlDataAdapter _MonDataAdapter3;
    				System.Data.DataTable _MaDataTable3;
     
    				// RECUPERER La configMat
    				string RequeteSQL3 = "SELECT M_CONFMAT FROM MACHINE WHERE M_CONFMAT='" + ConfigMachine.Text + "'";
     
    				_MonDataAdapter3 = new SqlDataAdapter(RequeteSQL3, connection);
     
    				_MaDataTable3 = new DataTable();
    				_MonDataAdapter3.Fill(_MaDataTable3);  */
    merci d'avance!!

  10. #10
    Membre extrêmement actif Avatar de fally
    Homme Profil pro
    Développeur .Net / BI
    Inscrit en
    Novembre 2007
    Messages
    966
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Bénin

    Informations professionnelles :
    Activité : Développeur .Net / BI

    Informations forums :
    Inscription : Novembre 2007
    Messages : 966
    Points : 1 173
    Points
    1 173
    Par défaut
    Voila, j'ai une application sous VisualStudio.Net2003 et une base de données SqlServer2000.
    Dans cette application, j'ai des renseignements sur le clients, le contact et la machine....
    Imaginon que le client, le contact mais aussi la machine existe déja dans la base SqlServer 2000. Je voudrais que l'utilisateur de cette application puisse modifier la configuration de la machine et qu'en appuyant sur un bouton cela enregistre la modification effectuées sur la configuration de la machine.

    EXEMPLE : configMachine = 5Go. L'utilisateur change '5Go' en '15Go'. Je souhaiterais que dans la base au lieu d'avoir 5 on a 15 Go après avoir cliqué sur le bouton.
    Je suppose que
    après avoir cliqué sur le bouton.
    veut dire "le bouton pour enregister les modifications" donc je te propose ceci :
    Dans ta table qui contient la "machine" tu as une clé ( c'est a dire un champ qui ne peut pas se répéter : un code) et dis a sql server ceci : "change la configuration de la machine; donne lui pour valeur 15Go mais seulement là où le code la machine est égale à tant" tu vois un peu?
    ta requete serait donc de ce genre là :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     string requete = "update machine set configmachine = '15Go' where mon_champ_code_machine = 'le_code_choisi' ";

  11. #11
    Expert éminent sénior
    Avatar de Skyounet
    Homme Profil pro
    Software Engineer
    Inscrit en
    Mars 2005
    Messages
    6 380
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Software Engineer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 6 380
    Points : 13 380
    Points
    13 380
    Par défaut
    Oui mais a priori il est en mode déconnecté donc je lui suggérais de modifier sa DataTable et de faire update avec son Adapter.
    Introduction à Silverlight 4 (new) ; Localisation d'une application Silverlight (new) ;
    Mon espace perso[/B]

    La connaissance s’acquiert par l’expérience, tout le reste n’est que de l’information. Albert Einstein[/SIZE]

  12. #12
    Membre averti Avatar de Contrec
    Homme Profil pro
    Inscrit en
    Mars 2005
    Messages
    597
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38

    Informations forums :
    Inscription : Mars 2005
    Messages : 597
    Points : 342
    Points
    342
    Par défaut
    Skyrunner +1

    1) Chargement des données en mode déconnecté (DataTable avec TableAdapter ou autres).

    2) Modifications par l'utilisateur.

    3) Update du DataTable par l'Adapter (entraine la modif dans la source de données).

    4) MAJ du DataTable si nécéssaire (DataTable.AcceptChanges()).

    Tout ça en mode déconnecté.
    Contrec

  13. #13
    Membre extrêmement actif Avatar de fally
    Homme Profil pro
    Développeur .Net / BI
    Inscrit en
    Novembre 2007
    Messages
    966
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Bénin

    Informations professionnelles :
    Activité : Développeur .Net / BI

    Informations forums :
    Inscription : Novembre 2007
    Messages : 966
    Points : 1 173
    Points
    1 173
    Par défaut
    [QUOTE=Contrec;2976135]Skyrunner +1QUOTE]
    Tu trouves? et pourquoi? explique où se trouve mon erreur

  14. #14
    Membre averti Avatar de Contrec
    Homme Profil pro
    Inscrit en
    Mars 2005
    Messages
    597
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38

    Informations forums :
    Inscription : Mars 2005
    Messages : 597
    Points : 342
    Points
    342
    Par défaut
    Car si il est en mode connecté, son Adapteur va automatiquement lancer les requêtes SQL correspondantes pour mettre à jour la BDD sans avoir à créer une requête (Update ... Set ... Where ID = ...). Si il possède un DataSet ou DataTable avec des données et que l'utilisateur fasse 150 changements (dont des ajouts, des modifs, des suppressions etc..).

    La méthode Update de ton Adapteur va regarder pour chaque ligne (row) de ton DataSet ou DataTable son état et exécuter la bonne requête SQL automatiquement.

    Si la row en question a été supprimée, la requête sera "Delete From..."

    Si la row en question a été ajoutée, "Insert into..."

    Si la row en question a été modifiée "Update ... Where..."

    Tu n'as donc pas à te soucier de créer tes propres requêtes en strong pour les éxécuter.


    Maintenant, si l'utilisateur n'a qu'un seul champ à modifier, ta solution est mieux appropriée : Tu récupère la nouvelle valeur et lors de l'enregistrement :

    "update machine set configmachine = '15Go' where mon_champ_code_machine = 'le_code_choisi' ";

    PS : Il n'y a pas d'erreur dans ton code.
    Contrec

  15. #15
    Débutant  
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    1 571
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 1 571
    Points : 353
    Points
    353
    Par défaut
    Tout d'abord merci pour vos renseignements.

    Donc j'ai essayé cela :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    SqlCommand commander;
    					SqlConnection connection;
    					connection = new SqlConnection("Data Source=DIST-5B8D87E3A9;Initial Catalog=DistribInfo;Integrated Security=SSPI");
    				connection.Open();
    				commander = new SqlCommand("UPDATE MACHINE SET M_CONFMAT = '" + ConfigMachine.Text + "' WHERE M_IDMAT = '" + NumMachine.Text + "'");
    				commander.ExecuteNonQuery();
    				connection.Close();
    mais le problème c'est que ça fonctionne pas car il me dit la chose suivante :
    C:\Documents and Settings\Propriétaire\Mes documents\Visual Studio Projects\SuiviClient_Distrib'Info\NouvelleIntervention.cs(1291): Une variable locale nommée 'connection' ne peut pas être déclarée dans cette portée, car elle modifierait la signification de 'connection', déjà utilisée dans une portée 'parent ou en cours' pour désigner autre chose
    correspondant a celui la :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SqlConnection connection;
    tout en sachant que : le code complet du bouton es le suivant :
    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
    private void Valider_Click(object sender, System.EventArgs e)
    		{
    			// Code permettant l'enregistrement des résultats
    			// dans la base de données SqlServer se nommant DistribInfo 
    			SqlConnection connection;
    			connection = new SqlConnection("Data Source=DIST-5B8D87E3A9;Initial Catalog=DistribInfo;Integrated Security=SSPI");
    			connection.Open();        
    			try
    			{
    				SqlDataAdapter _MonDataAdapter;
    				System.Data.DataTable _MaDataTable;
     
    				// RECUPERER LA LISTE DES CLIENTS QUI ONT POUR NUMERO NUMCLT.TEXT
    				string RequeteSQL = "SELECT C_NOMCLT FROM CLIENT WHERE C_NOMCLT='" + NomClient.Text + "'";
     
    				_MonDataAdapter = new SqlDataAdapter(RequeteSQL, connection);
     
    				_MaDataTable = new DataTable();
    				_MonDataAdapter.Fill(_MaDataTable);
     
     
    				SqlDataAdapter _MonDataAdapter1;
    				System.Data.DataTable _MaDataTable1;
     
    				// RECUPERER LA LISTE DES CONTACTS QUI ONT POUR NUMERO NUMCTACT.TEXT
    				string RequeteSQL1 = "SELECT CT_NUMCTACT FROM CONTACT WHERE CT_NUMCTACT='" + NumContact.Text + "'";
     
    				_MonDataAdapter1 = new SqlDataAdapter(RequeteSQL1, connection);
     
    				_MaDataTable1 = new DataTable();
    				_MonDataAdapter1.Fill(_MaDataTable1);
     
     
    				SqlDataAdapter _MonDataAdapter2;
    				System.Data.DataTable _MaDataTable2;
     
    				// RECUPERER LA LISTE DES MACHINES
    				string RequeteSQL2 = "SELECT M_IDMAT FROM MACHINE WHERE M_IDMAT='" + NumMachine.Text + "'";
     
    				_MonDataAdapter2 = new SqlDataAdapter(RequeteSQL2, connection);
     
    				_MaDataTable2 = new DataTable();
    				_MonDataAdapter2.Fill(_MaDataTable2);
     
     
     
    				SqlDataAdapter _MonDataAdapter4;
    				System.Data.DataTable _MaDataTable4;
     
    				// RECUPERER LA LISTE DES MACHINES
    				string RequeteSQL4 = "SELECT IN_RESINTER FROM INTERVENTION WHERE IN_RESINTER='" + RaisonInter.Text + "'";
     
    				_MonDataAdapter4 = new SqlDataAdapter(RequeteSQL4, connection);
     
    				_MaDataTable4 = new DataTable();
    				_MonDataAdapter4.Fill(_MaDataTable4);
     
     
    			/*	SqlDataAdapter _MonDataAdapter5;
    				System.Data.DataTable _MaDataTable5;
     
    				// RECUPERER La configMat
    				string RequeteSQL5 = "SELECT M_CONFMAT FROM MACHINE WHERE M_CONFMAT='" + ConfigMachine.Text + "'";
     
    				_MonDataAdapter5 = new SqlDataAdapter(RequeteSQL5, connection);
     
    				_MaDataTable5 = new DataTable();
    				_MonDataAdapter5.Fill(_MaDataTable5);*/
     
     
    				string fax="<NULL>";
    				if(!faxCtact.Text.Equals("FaxContact"))
    				{
    					fax=faxCtact.Text;
    				}
     
    				string resp="<NULL>";
    				if(!RespCtact.Text.Equals("responsableContact"))
    				{
    					resp=RespCtact.Text;
    				}
     
    				string NomUtil="<NULL>";
    				if(!NomUtMachine.Text.Equals("Nom utilisateur"))
    				{
    					NomUtil=NomUtMachine.Text;
    				}
     
    				string RapRespUtil="<NULL>";
    				if(!RespUt.Text.Equals("ResponsableUtilisateur"))
    				{
    					RapRespUtil=RespUt.Text;
    				}
     
    				string Depo="<NULL>";
    				if(!Depositaire.Text.Equals("NomDépositaire"))
    				{
    					Depo=Depositaire.Text;
    				}
     
    				string Recep="<NULL>";
    				if(!Receptionneur.Text.Equals("NomRéceptionneur"))
    				{
    					Recep=Receptionneur.Text;
    				}
     
    				// SI CLIENT NON EXISTANT
    				if (_MaDataTable.Rows.Count == 0)  
    				{ 
    					// Enregistrement des informations sur le client
    					SqlParameter paramNClt = new SqlParameter("@NumClt", SqlDbType.VarChar, 13);
    					paramNClt.Value = NumClt.Text;
    					SqlParameter paramNomClt = new SqlParameter("@NomClt", SqlDbType.Char, 16);
    					paramNomClt.Value = NomClient.Text;
    					SqlParameter paramStatuClt = new SqlParameter("@StatuClt", SqlDbType.Char, 12);
    					paramStatuClt.Value = StatuClient.SelectedItem.ToString();
     
    					string strSql = string.Format("INSERT INTO CLIENT(C_NUMCLT, C_NOMCLT, C_STATUCLT) VALUES({0}, {1}, {2})", paramNClt.ParameterName, paramNomClt.ParameterName, paramStatuClt.ParameterName);
     
    					SqlCommand cmd = new SqlCommand(strSql, connection);
    					cmd.Parameters.Add(paramNClt);
    					cmd.Parameters.Add(paramNomClt);
    					cmd.Parameters.Add(paramStatuClt);  			
    					cmd.ExecuteNonQuery();
     
     
    					// Enregistrement des informations sur le contact
    					SqlParameter paramNumCtact = new SqlParameter("@NumCtact", SqlDbType.VarChar, 13);
    					paramNumCtact.Value = NumContact.Text;
    					SqlParameter paramNumClt = new SqlParameter("@NumClt", SqlDbType.VarChar, 13);
    					paramNumClt.Value = NumClt.Text;
    					SqlParameter paramNomCtact = new SqlParameter("@NomCtact", SqlDbType.Char, 20);
    					paramNomCtact.Value = NomContact.Text;
    					SqlParameter paramPnmCtact = new SqlParameter("@PnmCtact", SqlDbType.Char, 20);
    					paramPnmCtact.Value = PrenomContact.Text;
    					SqlParameter paramTelCtact = new SqlParameter("@TelCtact", SqlDbType.VarChar, 15);
    					paramTelCtact.Value = telContact.Text;
    					SqlParameter paramAnnivCtact = new SqlParameter("@AnnivCtact", SqlDbType.DateTime, 8);
    					paramAnnivCtact.Value = annivCtact.Text;
    					SqlParameter paramFctCtact = new SqlParameter("@FctCtact", SqlDbType.Char, 120);
    					paramFctCtact.Value = FctContact.Text;
     
    					string strSql1 = string.Format("INSERT INTO CONTACT(CT_NUMCTACT, CT_NUMCLT, CT_NOMCTACT, CT_PNMCTACT, CT_TELCTACT, CT_FAXCTACT, CT_ANICTACT, CT_FCTCTACT, CT_RSPCTACT) VALUES({0}, {1}, {2}, {3}, {4}, '" + fax + "', {5}, {6}, '" + resp + "')",paramNumCtact.ParameterName, paramNumClt.ParameterName, paramNomCtact.ParameterName, paramPnmCtact.ParameterName, paramTelCtact.ParameterName, paramAnnivCtact.ParameterName, paramFctCtact.ParameterName); 
     
    					SqlCommand command = new SqlCommand(strSql1, connection);
    					command.Parameters.Add(paramNumCtact);
    					command.Parameters.Add(paramNumClt);
    					command.Parameters.Add(paramNomCtact);
    					command.Parameters.Add(paramPnmCtact);
    					command.Parameters.Add(paramTelCtact);
    					command.Parameters.Add(paramAnnivCtact);
    					command.Parameters.Add(paramFctCtact);
    					command.ExecuteNonQuery();
     
     
    					// Enregistrement des informations sur la machine
    					SqlParameter paramNClient = new SqlParameter("@NumClt", SqlDbType.VarChar, 13);
    					paramNClient.Value = NumClt.Text;
    					SqlParameter paramIdMat = new SqlParameter("@IdMat", SqlDbType.Decimal, 13);
    					paramIdMat.Value = decimal.Parse(NumMachine.Text);
    					SqlParameter paramNumContact = new SqlParameter("@NumCtact", SqlDbType.VarChar, 13);
    					paramNumContact.Value = NumContact.Text;
    					SqlParameter paramNomMat = new SqlParameter("@NomMat", SqlDbType.VarChar, 50);
    					paramNomMat.Value = NomMachine.Text;
    					SqlParameter paramConfMat = new SqlParameter("@ConfMat", SqlDbType.VarChar, 150);
    					paramConfMat.Value = ConfigMachine.Text;
    					SqlParameter paramRapResInter = new SqlParameter("@RapresInter", SqlDbType.Char, 50);
    					paramRapResInter.Value = RaisonInter.Text;
     
    					string strSql2 = string.Format("INSERT INTO MACHINE(M_NUMCLT, M_IDMAT, M_NUMCTACT, M_NOMMAT, M_CONFMAT, M_NOMUTIL, M_RAP_RESP, M_RESINTER) VALUES({0}, {1}, {2}, {3}, {4}, '" + NomUtil + "', '" + RapRespUtil + "', {5})", paramNClient.ParameterName, paramIdMat.ParameterName, paramNumContact.ParameterName, paramNomMat.ParameterName, paramConfMat.ParameterName, paramRapResInter.ParameterName);
     
    					SqlCommand Command = new SqlCommand(strSql2, connection);
    					Command.Parameters.Add(paramNClient);
    					Command.Parameters.Add(paramIdMat);
    					Command.Parameters.Add(paramNumContact);
    					Command.Parameters.Add(paramNomMat);
    					Command.Parameters.Add(paramConfMat);
    					Command.Parameters.Add(paramRapResInter);
    					Command.ExecuteNonQuery();
     
     
    					// Enregistrement des informations de l'intervention
    					SqlParameter paramNInter = new SqlParameter("@NumInter", SqlDbType.VarChar, 15);
    					paramNInter.Value = NumIntervention.Text;
    					SqlParameter paramNumeroClt = new SqlParameter("@NumClt", SqlDbType.VarChar, 13);
    					paramNumeroClt.Value = NumClt.Text;
    					SqlParameter paramNClt1 = new SqlParameter("@NumClt1", SqlDbType.VarChar, 13);
    					paramNClt1.Value = NumClt.Text;  
    					SqlParameter paramIDMat = new SqlParameter("@IdMat", SqlDbType.Decimal, 9);
    					paramIDMat.Value = decimal.Parse(NumMachine.Text);
    					SqlParameter paramResInter = new SqlParameter("@ResInter", SqlDbType.VarChar, 250);
    					paramResInter.Value = RaisonInter.Text;
    					SqlParameter paramLieuInter = new SqlParameter("@LieuInter", SqlDbType.Text, 16);
    					paramLieuInter.Value = LieuInter.SelectedItem.ToString();
     
    					string strSql3 = string.Format("INSERT INTO INTERVENTION(IN_NUMINTER, IN_NUMCLT, IN_M_NUMCLT, IN_IDMAT, IN_RESINTER, IN_ETAINTER, IN_LIEINTER, IN_DEPOMAT, IN_RECEPMAT) VALUES({0},{1},{2}, {3}, {4}, 'demande', {5}, '" + Depo + "', '" + Recep + "')", paramNInter.ParameterName, paramNumeroClt.ParameterName, paramNClt1.ParameterName, paramIDMat.ParameterName, paramResInter.ParameterName, paramLieuInter.ParameterName);
     
    					SqlCommand comde = new SqlCommand(strSql3, connection);
    					comde.Parameters.Add(paramNInter);
    					comde.Parameters.Add(paramNumeroClt);
    					comde.Parameters.Add(paramNClt1); 
    					comde.Parameters.Add(paramIDMat);
    					comde.Parameters.Add(paramResInter);
    					comde.Parameters.Add(paramLieuInter);
    					comde.ExecuteNonQuery(); 
    				}
    					// Sinon si le NuméroContact est inexistant
    				else if (_MaDataTable1.Rows.Count == 0)
    				{
    					// Enregistrement des informations sur le contact
    					SqlParameter paramNumCtact = new SqlParameter("@NumCtact", SqlDbType.VarChar, 13);
    					paramNumCtact.Value = NumContact.Text;
    					SqlParameter paramNumClt = new SqlParameter("@NumClt", SqlDbType.VarChar, 13);
    					paramNumClt.Value = NumClt.Text;
    					SqlParameter paramNomCtact = new SqlParameter("@NomCtact", SqlDbType.Char, 20);
    					paramNomCtact.Value = NomContact.Text;
    					SqlParameter paramPnmCtact = new SqlParameter("@PnmCtact", SqlDbType.Char, 20);
    					paramPnmCtact.Value = PrenomContact.Text;
    					SqlParameter paramTelCtact = new SqlParameter("@TelCtact", SqlDbType.VarChar, 15);
    					paramTelCtact.Value = telContact.Text;
    					SqlParameter paramAnnivCtact = new SqlParameter("@AnnivCtact", SqlDbType.DateTime, 8);
    					paramAnnivCtact.Value = annivCtact.Text;
    					SqlParameter paramFctCtact = new SqlParameter("@FctCtact", SqlDbType.Char, 120);
    					paramFctCtact.Value = FctContact.Text;
     
    					string strSql1 = string.Format("INSERT INTO CONTACT(CT_NUMCTACT, CT_NUMCLT, CT_NOMCTACT, CT_PNMCTACT, CT_TELCTACT, CT_FAXCTACT, CT_ANICTACT, CT_FCTCTACT, CT_RSPCTACT) VALUES({0}, {1}, {2}, {3}, {4}, '" + fax + "', {5}, {6},  '" + resp + "' )",paramNumCtact.ParameterName, paramNumClt.ParameterName, paramNomCtact.ParameterName, paramPnmCtact.ParameterName, paramTelCtact.ParameterName, paramAnnivCtact.ParameterName, paramFctCtact.ParameterName); 
     
    					SqlCommand command = new SqlCommand(strSql1, connection);
    					command.Parameters.Add(paramNumCtact);
    					command.Parameters.Add(paramNumClt);
    					command.Parameters.Add(paramNomCtact);
    					command.Parameters.Add(paramPnmCtact);
    					command.Parameters.Add(paramTelCtact);
    					command.Parameters.Add(paramAnnivCtact);
    					command.Parameters.Add(paramFctCtact);
    					command.ExecuteNonQuery();
     
     
    					// Enregistrement des informations de l'intervention
    					SqlParameter paramNInter = new SqlParameter("@NumInter", SqlDbType.VarChar, 15);
    					paramNInter.Value = NumIntervention.Text;
    					SqlParameter paramNumeroClt = new SqlParameter("@NumClt", SqlDbType.VarChar, 13);
    					paramNumeroClt.Value = NumClt.Text;
    					SqlParameter paramNClt1 = new SqlParameter("@NumClt1", SqlDbType.VarChar, 13);
    					paramNClt1.Value = NumClt.Text;  
    					SqlParameter paramIDMat = new SqlParameter("@IdMat", SqlDbType.Decimal, 9);
    					paramIDMat.Value = decimal.Parse(NumMachine.Text);
    					SqlParameter paramResInter = new SqlParameter("@ResInter", SqlDbType.VarChar, 250);
    					paramResInter.Value = RaisonInter.Text;
    					SqlParameter paramLieuInter = new SqlParameter("@LieuInter", SqlDbType.Text, 16);
    					paramLieuInter.Value = LieuInter.SelectedItem.ToString();
     
    					string strSql3 = string.Format("INSERT INTO INTERVENTION(IN_NUMINTER, IN_NUMCLT, IN_M_NUMCLT, IN_IDMAT, IN_RESINTER, IN_ETAINTER, IN_LIEINTER, IN_DEPOMAT, IN_RECEPMAT) VALUES({0},{1},{2}, {3}, {4}, 'demande', {5}, '" + Depo + "', '" + Recep + "')", paramNInter.ParameterName, paramNumeroClt.ParameterName, paramNClt1.ParameterName, paramIDMat.ParameterName, paramResInter.ParameterName, paramLieuInter.ParameterName);
     
    					SqlCommand comde = new SqlCommand(strSql3, connection);
    					comde.Parameters.Add(paramNInter);
    					comde.Parameters.Add(paramNumeroClt);
    					comde.Parameters.Add(paramNClt1); 
    					comde.Parameters.Add(paramIDMat);
    					comde.Parameters.Add(paramResInter);
    					comde.Parameters.Add(paramLieuInter);
    					comde.ExecuteNonQuery();
    				}
    					// Sinon si le NumMachine est inexistant
    				else if (_MaDataTable2.Rows.Count == 0)
    				{
    					// Enregistrement des informations sur la machine
    					SqlParameter paramNClient = new SqlParameter("@NumClt", SqlDbType.VarChar, 13);
    					paramNClient.Value = NumClt.Text;
    					SqlParameter paramIdMat = new SqlParameter("@IdMat", SqlDbType.Decimal, 13);
    					paramIdMat.Value = decimal.Parse(NumMachine.Text);
    					SqlParameter paramNumContact = new SqlParameter("@NumCtact", SqlDbType.VarChar, 13);
    					paramNumContact.Value = NumContact.Text;
    					SqlParameter paramNomMat = new SqlParameter("@NomMat", SqlDbType.VarChar, 50);
    					paramNomMat.Value = NomMachine.Text;
    					SqlParameter paramConfMat = new SqlParameter("@ConfMat", SqlDbType.VarChar, 150);
    					paramConfMat.Value = ConfigMachine.Text;
    					SqlParameter paramRapResInter = new SqlParameter("@RapresInter", SqlDbType.Char, 50);
    					paramRapResInter.Value = RaisonInter.Text;
     
    					string strSql2 = string.Format("INSERT INTO MACHINE(M_NUMCLT, M_IDMAT, M_NUMCTACT, M_NOMMAT, M_CONFMAT, M_NOMUTIL, M_RAP_RESP, M_RESINTER) VALUES({0}, {1}, {2}, {3}, {4}, '" + NomUtil + "', '" + RapRespUtil + "', {5})", paramNClient.ParameterName, paramIdMat.ParameterName, paramNumContact.ParameterName, paramNomMat.ParameterName, paramConfMat.ParameterName, paramRapResInter.ParameterName);
     
    					SqlCommand Command = new SqlCommand(strSql2, connection);
    					Command.Parameters.Add(paramNClient);
    					Command.Parameters.Add(paramIdMat);
    					Command.Parameters.Add(paramNumContact);
    					Command.Parameters.Add(paramNomMat);
    					Command.Parameters.Add(paramConfMat);
    					Command.Parameters.Add(paramRapResInter);
    					Command.ExecuteNonQuery();
     
     
    					// Enregistrement des informations de l'intervention
    					SqlParameter paramNInter = new SqlParameter("@NumInter", SqlDbType.VarChar, 15);
    					paramNInter.Value = NumIntervention.Text;
    					SqlParameter paramNumeroClt = new SqlParameter("@NumClt", SqlDbType.VarChar, 13);
    					paramNumeroClt.Value = NumClt.Text;
    					SqlParameter paramNClt1 = new SqlParameter("@NumClt1", SqlDbType.VarChar, 13);
    					paramNClt1.Value = NumClt.Text;  
    					SqlParameter paramIDMat = new SqlParameter("@IdMat", SqlDbType.Decimal, 9);
    					paramIDMat.Value = decimal.Parse(NumMachine.Text);
    					SqlParameter paramResInter = new SqlParameter("@ResInter", SqlDbType.VarChar, 250);
    					paramResInter.Value = RaisonInter.Text;
    					SqlParameter paramLieuInter = new SqlParameter("@LieuInter", SqlDbType.Text, 16);
    					paramLieuInter.Value = LieuInter.SelectedItem.ToString();
     
    					string strSql3 = string.Format("INSERT INTO INTERVENTION(IN_NUMINTER, IN_NUMCLT, IN_M_NUMCLT, IN_IDMAT, IN_RESINTER, IN_ETAINTER, IN_LIEINTER, IN_DEPOMAT, IN_RECEPMAT) VALUES({0},{1},{2}, {3}, {4}, 'demande', {5}, '" + Depo + "', '" + Recep + "')", paramNInter.ParameterName, paramNumeroClt.ParameterName, paramNClt1.ParameterName, paramIDMat.ParameterName, paramResInter.ParameterName, paramLieuInter.ParameterName);
     
    					SqlCommand comde = new SqlCommand(strSql3, connection);
    					comde.Parameters.Add(paramNInter);
    					comde.Parameters.Add(paramNumeroClt);
    					comde.Parameters.Add(paramNClt1); 
    					comde.Parameters.Add(paramIDMat);
    					comde.Parameters.Add(paramResInter);
    					comde.Parameters.Add(paramLieuInter);
    					comde.ExecuteNonQuery();
     
    				}
    				else if (_MaDataTable4.Rows.Count == 0)
    				{
    					// Enregistrement des informations de l'intervention
    					SqlParameter paramNInter = new SqlParameter("@NumInter", SqlDbType.VarChar, 15);
    					paramNInter.Value = NumIntervention.Text;
    					SqlParameter paramNClt = new SqlParameter("@NumClt", SqlDbType.VarChar, 13);
    					paramNClt.Value = NumClt.Text;
    					SqlParameter paramNClt1 = new SqlParameter("@NumClt1", SqlDbType.VarChar, 13);
    					paramNClt1.Value = NumClt.Text;  
    					SqlParameter paramIdMat = new SqlParameter("@IdMat", SqlDbType.Decimal, 9);
    					paramIdMat.Value = decimal.Parse(NumMachine.Text);
    					SqlParameter paramResInter = new SqlParameter("@ResInter", SqlDbType.VarChar, 250);
    					paramResInter.Value = RaisonInter.Text;
    					SqlParameter paramLieuInter = new SqlParameter("@LieuInter", SqlDbType.Text, 16);
    					paramLieuInter.Value = LieuInter.SelectedItem.ToString();
     
    					string strSql = string.Format("INSERT INTO INTERVENTION(IN_NUMINTER, IN_NUMCLT, IN_M_NUMCLT, IN_IDMAT, IN_RESINTER, IN_ETAINTER, IN_LIEINTER, IN_DEPOMAT, IN_RECEPMAT) VALUES({0},{1},{2}, {3}, {4}, 'demande', {5}, '" + Depo + "', '" + Recep + "')", paramNInter.ParameterName, paramNClt.ParameterName, paramNClt1.ParameterName, paramIdMat.ParameterName, paramResInter.ParameterName, paramLieuInter.ParameterName);
     
    					SqlCommand cmd = new SqlCommand(strSql, connection);
    					cmd.Parameters.Add(paramNInter);
    					cmd.Parameters.Add(paramNClt);
    					cmd.Parameters.Add(paramNClt1); 
    					cmd.Parameters.Add(paramIdMat);
    					cmd.Parameters.Add(paramResInter);
    					cmd.Parameters.Add(paramLieuInter);
     
    					cmd.ExecuteNonQuery(); 
    				} 
    			//	else if (_MaDataTable5.Rows.Count > 0) and (ConfigMachine.Text != M_CONFMAT)
    			//	{
    					SqlCommand commander;
    					SqlConnection connection;
    					connection = new SqlConnection("Data Source=DIST-5B8D87E3A9;Initial Catalog=DistribInfo;Integrated Security=SSPI");
    				//	string requete = ("UPDATE MACHINE SET M_CONFMAT = '" + ConfigMachine.Text + "' WHERE M_IDMAT = '" + NumMachine.Text + "'");
    				connection.Open();
    				commander = new SqlCommand("UPDATE MACHINE SET M_CONFMAT = '" + ConfigMachine.Text + "' WHERE M_IDMAT = '" + NumMachine.Text + "'");
    				commander.ExecuteNonQuery();
    				connection.Close();
    			//	}
     
     
    			} 
    			catch(Exception ex)
    			{
    				// Ici le ToString te renvoi suffisamment d'infos
    				MessageBox.Show(ex.ToString());
    			}
    			finally
    			{
    				connection.Close();
    			}
    		}
    merci d'avance!!

  16. #16
    Membre averti Avatar de Contrec
    Homme Profil pro
    Inscrit en
    Mars 2005
    Messages
    597
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38

    Informations forums :
    Inscription : Mars 2005
    Messages : 597
    Points : 342
    Points
    342
    Par défaut
    Ton message d'erreur (si je comprends bien le français) signifie que ton projet a déjà déclaré une variable se nommant "connection" donc tu dois renommer la tienne (par exemple MaConnection).
    Contrec

  17. #17
    Débutant  
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    1 571
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 1 571
    Points : 353
    Points
    353
    Par défaut
    C'est bon je n'est plus cette erreur mais par ontre lorsque j'exécute mon application, il me dit qu "connection na pas été initialisé" (un truc du genre)

    Je vois pas comment faire.

    merci d'avance!!

  18. #18
    Membre averti Avatar de Contrec
    Homme Profil pro
    Inscrit en
    Mars 2005
    Messages
    597
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38

    Informations forums :
    Inscription : Mars 2005
    Messages : 597
    Points : 342
    Points
    342
    Par défaut
    Tu es sûr que ton projet ne fait pas déjà une connexion par défaut ? (Si une variable connexion est en cours, c'est qu'une connexion peut être utilisée et toi tu en relances une autre...).

    Sinon tu es sûr de ta ConnexionString :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    connection = new SqlConnection("Data Source=DIST-5B8D87E3A9;Initial Catalog=DistribInfo;Integrated Security=SSPI");
    Contrec

  19. #19
    Expert éminent sénior
    Avatar de Skyounet
    Homme Profil pro
    Software Engineer
    Inscrit en
    Mars 2005
    Messages
    6 380
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Software Engineer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 6 380
    Points : 13 380
    Points
    13 380
    Par défaut
    Tu es sur que tu connais le C# avant de faire de l'ADO.NET ?
    Introduction à Silverlight 4 (new) ; Localisation d'une application Silverlight (new) ;
    Mon espace perso[/B]

    La connaissance s’acquiert par l’expérience, tout le reste n’est que de l’information. Albert Einstein[/SIZE]

  20. #20
    Débutant  
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    1 571
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 1 571
    Points : 353
    Points
    353
    Par défaut réponse à Contrec
    C'est bon ça fonctionne, j'avais oublié de mettre connection au niveau de la requête.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    commander = new SqlCommand("UPDATE MACHINE SET M_CONFMAT = '" + ConfigMachine.Text + "' WHERE M_IDMAT = '" + NumMachine.Text + "'", connection);
    merci pour tout!!

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. Réponses: 3
    Dernier message: 07/02/2015, 14h08
  2. Problème de mise à jour des données sur un onglet
    Par PenPen_lepingouin dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 26/06/2008, 17h49
  3. Réponses: 7
    Dernier message: 09/07/2007, 21h14
  4. [MySQL] problème de syntaxe sur la récupération des données
    Par soshin dans le forum PHP & Base de données
    Réponses: 28
    Dernier message: 23/11/2006, 12h34
  5. Réponses: 6
    Dernier message: 15/02/2006, 14h02

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