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 d'enregistrement dans une base SqlServer


Sujet :

C#

  1. #201
    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
    Voila j'ai encore besoin de votre aide, suis vraiment désolé.

    Donc j'ai réaliser le code qui me permettrais de rentrer les information concernant le client dans la base.

    Ensuite je souhaiterais rentrer les renseignement correspondant au contact correspondant au client crééé donc NumClt est clé étrangére dans la table contact.

    J'ai essayé ceci mais ça m'enregistre juste le client et non le contact.

    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
     
    // renseignement 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);
     
     
    // renseignement contact
    					SqlParameter paramNumCtact = new SqlParameter("@NumCtact", SqlDbType.VarChar, 13);
    					paramNumCtact.Value = NumContact.Text;
     
    					string strSql1 = string.Format("INSERT INTO CONTACT(CT_NUMCTACT, CT_NUMCLT, CT_NOMCTACT, CT_PNMCTACT, CT_TELCTACT, CT_ANICTACT, CT_FCTCTACT) VALUES({0}, 'kia', 'bergo', 'marco', '33445724', '10/10/1986', 'gérant')",paramNumCtact.ParameterName); 
     
    					SqlCommand command = new SqlCommand(strSql1, connection);
    					command.Parameters.Add(paramNumCtact);
    									cmd.ExecuteNonQuery();
    ya t'il un autre moyen??

    Faut savoir que le NumCtact est de type Varchar(13) dans la base et dans mon application c'est un TextBox.

    merci d'avance!!

  2. #202
    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 bon j'ai réussit c'étais tout bête!!

    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
    		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();
     
     
    					SqlParameter paramNumCtact = new SqlParameter("@NumCtact", SqlDbType.VarChar, 13);
    					paramNumCtact.Value = NumContact.Text;
     
    					//	SqlParameter paramNumClt = new SqlParameter("@NumClt", SqlDbType.VarChar, 13);
    					//	paramNumClt.Value = NumClt.Text;
     
    					string strSql1 = string.Format("INSERT INTO CONTACT(CT_NUMCTACT, CT_NUMCLT, CT_NOMCTACT, CT_PNMCTACT, CT_TELCTACT, CT_ANICTACT, CT_FCTCTACT) VALUES({0}, 'kia', 'bergo', 'marco', '33445724', '10/10/1986', 'gérant')",paramNumCtact.ParameterName); 
     
    					SqlCommand command = new SqlCommand(strSql1, connection);
    					command.Parameters.Add(paramNumCtact);
    					//	command.Parameters.Add(paramNumClt);
     
    					command.ExecuteNonQuery();
     
     
    				}

  3. #203
    En attente de confirmation mail
    Inscrit en
    Août 2006
    Messages
    550
    Détails du profil
    Informations personnelles :
    Âge : 49

    Informations forums :
    Inscription : Août 2006
    Messages : 550
    Points : 669
    Points
    669
    Par défaut
    Citation Envoyé par loic20h28 Voir le message

    vos compliment me touche et me font rire a la fois aussi!!

    Je savez pas que je pourrais devenir comme bill gate!!C un honneur que l'on me fais la!!
    On se marre bien aussi de notre coté, je t'assure !!

  4. #204
    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
    On se marre bien aussi de notre coté, je t'assure !!
    je sens de l'ironnie dans l'air venant de ta pars, mais bizarrement ca me fais rien tête parce que j'ai réussi a peu prêt tout seul!!



  5. #205
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    Citation Envoyé par loic20h28 Voir le message
    je sens de l'ironnie dans l'air venant de ta pars, mais bizarrement ca me fais rien tête parce que j'ai réussi a peu prêt tout seul!!
    Vu le nombre de personne qui t'ont aidé tu ne peux pas dire cela, c'est de l'ingratitude la plus total !!!!

  6. #206
    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 à ced600
    Je suis désolé ced600, j'avais oublié des lol, car bien entendu je plaisanté t'inquiète pas, j'en suis bien reconnaissant a ceux qui m'on aidé.

    encore désolé!! je voulais pas etre ingras!!

  7. #207
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    Citation Envoyé par loic20h28 Voir le message
    Je suis désolé ced600, j'avais oublié des lol, car bien entendu je plaisanté t'inquiète pas, j'en suis bien reconnaissant a ceux qui m'on aidé.

    encore désolé!! je voulais pas etre ingras!!
    ok ca va alors.

  8. #208
    Membre habitué Avatar de salihovic
    Inscrit en
    Février 2007
    Messages
    255
    Détails du profil
    Informations forums :
    Inscription : Février 2007
    Messages : 255
    Points : 135
    Points
    135
    Par défaut
    félicitation loic20h28
    c'est bien de trouver la solution

  9. #209
    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
    merci salihovic!!


  10. #210
    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 relance du sujet
    Bonjour tout le monde,

    Voila le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    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
    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(); 	
     
    			SqlCommand commander;
    			commander = new SqlCommand("UPDATE MACHINE SET M_CONFMAT = '" + ConfigMachine.Text + "' WHERE M_IDMAT = '" + NumMachine.Text + "'", connection);
    			commander.ExecuteNonQuery();
     
    			try
    			{
    				// RECUPERER LA LISTE DES CLIENTS QUI ONT POUR NUMERO NUMCLT.TEXT
    				SqlDataAdapter _MonDataAdapter;
    				System.Data.DataTable _MaDataTable;
    				string RequeteSQL = "SELECT C_NOMCLT FROM CLIENT WHERE C_NOMCLT='" + NomClient.Text + "'";
    				_MonDataAdapter = new SqlDataAdapter(RequeteSQL, connection);
    				_MaDataTable = new DataTable();
    				_MonDataAdapter.Fill(_MaDataTable);
     
     
    				// RECUPERER LA LISTE DES CONTACTS QUI ONT POUR NUMERO NUMCTACT.TEXT
    				SqlDataAdapter _MonDataAdapter1;
    				System.Data.DataTable _MaDataTable1;
    				string RequeteSQL1 = "SELECT CT_NUMCTACT FROM CONTACT WHERE CT_NUMCTACT='" + NumContact.Text + "'";
    				_MonDataAdapter1 = new SqlDataAdapter(RequeteSQL1, connection);
    				_MaDataTable1 = new DataTable();
    				_MonDataAdapter1.Fill(_MaDataTable1);
     
     
     
    				// RECUPERER LA LISTE DES MACHINES
    				SqlDataAdapter _MonDataAdapter2;
    				System.Data.DataTable _MaDataTable2;
    				string RequeteSQL2 = "SELECT M_IDMAT FROM MACHINE WHERE M_IDMAT='" + NumMachine.Text + "'";
    				_MonDataAdapter2 = new SqlDataAdapter(RequeteSQL2, connection);
    				_MaDataTable2 = new DataTable();
    				_MonDataAdapter2.Fill(_MaDataTable2);
     
     
    				// RECUPERER LA LISTE DES MACHINES
    				SqlDataAdapter _MonDataAdapter3;
    				System.Data.DataTable _MaDataTable3;
    				string RequeteSQL3 = "SELECT IN_RESINTER FROM INTERVENTION WHERE IN_RESINTER='" + RaisonInter.Text + "'";
    				_MonDataAdapter3 = new SqlDataAdapter(RequeteSQL3, connection);
    				_MaDataTable3 = new DataTable();
    				_MonDataAdapter3.Fill(_MaDataTable3);
     
     
    				// Si le contact n'as pas de fax
    				// alors <NULL> sera affiché dans la base
    				string fax="<NULL>";
    				if(!faxCtact.Text.Equals(""))
    				{
    					fax=faxCtact.Text;
    				}
     
    				// Si le contact n'as pas de responsable
    				// alors <NULL> sera affiché dans la base
    				string resp="<NULL>";
    				if(!RespCtact.Text.Equals(""))
    				{
    					resp=RespCtact.Text;
    				}
     
    				// Si le nom de l'utilisateur de la machine
    				// n'est pas renseignés
    				// alors <NULL> sera affiché dans la base
    				string NomUtil="<NULL>";
    				if(!NomUtMachine.Text.Equals(""))
    				{
    					NomUtil=NomUtMachine.Text;
    				}
     
    				// Si le nom du responsable de l'utilisateur
    				// n'est pas renseigné
    				// alors <NULL> sera affiché dans la base
    				string RapRespUtil="<NULL>";
    				if(!RespUt.Text.Equals(""))
    				{
    					RapRespUtil=RespUt.Text;
    				}
     
    				// Si le dépositaire n'est pas renseigné
    				// alors <NULL> sera affiché dans la base
    				string Depo="<NULL>";
    				if(!Depositaire.Text.Equals(""))
    				{
    					Depo=Depositaire.Text;
    				} 
     
    				// Si le rceptionneur n'est pas renseigné
    				// alors <NULL> sera affiché dans la base
    				string Recep="<NULL>";
    				if(!Receptionneur.Text.Equals(""))
    				{
    					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 (_MaDataTable3.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(); 
    				} 
    			} 
    			catch(Exception ex)
    			{
    				MessageBox.Show(ex.ToString());
    			}
    			finally
    			{
    				connection.Close();
    			}
    		}
    Je comprend pas pourquoi car avant ça fonctionné.

    Lorsqu'il y a juste l'intervention a enregistrer dans la base, ça veux pas fonctionner.

    Je comprend pas pourquoi.

    merci d'avance!!

  11. #211
    Membre émérite Avatar de Guulh
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    2 160
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Septembre 2007
    Messages : 2 160
    Points : 2 925
    Points
    2 925
    Par défaut
    Dis, tu te vexes si je te dis que "ça marche pas, je comprends pas" est un compte-rendu d'erreur un brin léger et que même s'il nous restait un peu de bonne volonté on aurait un peu de mal à répondre sans aucune indication de ce qui pourrait bien déconner ?

  12. #212
    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 à Guulh
    J'aimerais bien t'en dire beaucoup plus mais je vais être obligé de te dire juste le message suivant:
    System.NullReferenceException: La référence d'objet n'est pas définie à une instance d'objet.
    Et j'ai remarqué qu'il n'allé pas jusqua la requête de :
    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
    	else if (_MaDataTable3.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(); 
    				} 
    			} 
    			catch(Exception ex)
    			{
    				MessageBox.Show(ex.ToString());
    			}
    			finally
    			{
    				connection.Close();
    			}
    merci d'avance!!

  13. #213
    Rédacteur
    Avatar de SaumonAgile
    Homme Profil pro
    Team leader
    Inscrit en
    Avril 2007
    Messages
    4 028
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Team leader
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2007
    Messages : 4 028
    Points : 6 334
    Points
    6 334
    Par défaut
    Quand tu débogues, il s'arrête à quelle ligne ?

  14. #214
    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 à SaumonAgile
    Lorsque je fais le debug, je me rend compte que'il s'arrête avant la requête.

    merci d'avance!!

  15. #215
    Rédacteur
    Avatar de SaumonAgile
    Homme Profil pro
    Team leader
    Inscrit en
    Avril 2007
    Messages
    4 028
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Team leader
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2007
    Messages : 4 028
    Points : 6 334
    Points
    6 334
    Par défaut
    Il s'arrête à quelle ligne de code exactement ?
    Je ne veux pas un "avant ci" ou "après ça".

    J'ai besoin de la ligne qui apparaît en jaune dans Visual Studio quand l'exception se déclenche, avec le message exact.

  16. #216
    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 à SaumonAgile
    Lorsque je fais du debug avec le pas à pas, le dernier code qui est souligné en jaune es tle suivant :
    paramLieuInter.Value = LieuInter.SelectedItem.ToString();
    et ensuite il m'affiche la chose suivante :
    System.NullReferenceException: La référence d'objet n'est pas définie à une instance d'objet.
    at SuiviClient_Distrib_Info.NouvelleIntervention.Valider_Click(Object sender, Events Args e) in c:\document and setting\propriétaire\mes documents\visual studios projects\suiviclient_Distrib'info\nouvelleIntervention.cs:line 1571
    Je pense t'avoir tout dit.

    merci d'avance!!

  17. #217
    Rédacteur
    Avatar de SaumonAgile
    Homme Profil pro
    Team leader
    Inscrit en
    Avril 2007
    Messages
    4 028
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Team leader
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2007
    Messages : 4 028
    Points : 6 334
    Points
    6 334
    Par défaut
    Et bien voila, c'est pas si compliqué, la prochaine fois, donne tout de suite ces infos, on gagnera du temps.

    Le problème est que SelectedItem doit être null. Tu dois tester avant en utilisant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    if (null != LieuInter.SelectedItem)
    {
        // J'exécute la requête
    }

  18. #218
    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
    Ce qui devrais me donner :
    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
    else if (_MaDataTable3.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();
     
    					if (null != LieuInter.SelectedItem)
    					{
    						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(); 
     
    					}...
    mais il m'affiche toujours la même erreur.

    merci d'avance!!

  19. #219
    Rédacteur
    Avatar de SaumonAgile
    Homme Profil pro
    Team leader
    Inscrit en
    Avril 2007
    Messages
    4 028
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Team leader
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2007
    Messages : 4 028
    Points : 6 334
    Points
    6 334
    Par défaut
    C'est normal tu fais le test après avoir accédé à SelectedItem...
    L'intérêt de faire le test, c'est que justement si c'est null, tu ne dois pas y accéder.

  20. #220
    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 à SaumonAgile
    Ben ui me si je fais :
    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
    else if (_MaDataTable3.Rows.Count == 0)
    					{
    						if (null != LieuInter.SelectedItem)
    						{
    							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 + "')", paramNumInter.ParameterName, paramNumClt.ParameterName, paramNumClt1.ParameterName, paramIDMachine.ParameterName, paramResonInter.ParameterName, paramLieInter.ParameterName);
     
    						}
    						// Enregistrement des informations de l'intervention
    						SqlParameter paramNumInter = new SqlParameter("@NumInter", SqlDbType.VarChar, 15);
    						paramNumInter.Value = NumIntervention.Text;
    						SqlParameter paramNumClt = new SqlParameter("@NumClt", SqlDbType.VarChar, 13);
    						paramNumClt.Value = NumClt.Text;
    						SqlParameter paramNumClt1 = new SqlParameter("@NumClt1", SqlDbType.VarChar, 13);
    						paramNumClt1.Value = NumClt.Text;  
    						SqlParameter paramIDMachine = new SqlParameter("@IdMat", SqlDbType.Decimal, 9);
    						paramIDMachine.Value = decimal.Parse(NumMachine.Text);
    						SqlParameter paramResonInter = new SqlParameter("@ResInter", SqlDbType.VarChar, 250);
    						paramResonInter.Value = RaisonInter.Text;
    						SqlParameter paramLieInter = new SqlParameter("@LieuInter", SqlDbType.Text, 16);
    						paramLieInter.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 + "')", paramNumInter.ParameterName, paramNumClt.ParameterName, paramNumClt1.ParameterName, paramIDMachine.ParameterName, paramResonInter.ParameterName, paramLieInter.ParameterName);
     
    						SqlCommand cmd = new SqlCommand(strSql, connection);
    						cmd.Parameters.Add(paramNumInter);
    						cmd.Parameters.Add(paramNumClt);
    						cmd.Parameters.Add(paramNumClt1); 
    						cmd.Parameters.Add(paramIDMachine);
    						cmd.Parameters.Add(paramResonInter);
    						cmd.Parameters.Add(paramLieInter);
    						cmd.ExecuteNonQuery(); 
     
    						if (DatePrisEnCharge.Checked == true)
    						{
    							cmd = new SqlCommand("UPDATE INTERVENTION SET IN_PRICHARG = '" + DatePrisEnCharge.Text + "' WHERE IN_NUMINTER = '" + NumIntervention.Text + "'", connection);
    							cmd.ExecuteNonQuery();
    						}
    						else if (DatePrisEnCharge.Checked == false)
    						{
    							cmd = new SqlCommand("UPDATE INTERVENTION SET IN_PRICHARG = 'NULL' WHERE IN_NUMINTER = '" + NumIntervention.Text + "'", connection);
    							cmd.ExecuteNonQuery();
    						} 
    					}
    					// Code permettant l'enregistrement des résultats
    					// dans la base de données SqlServer se nommant DistribInfo 
    					SqlCommand commander;
    					commander = new SqlCommand("UPDATE MACHINE SET M_CONFMAT = '" + ConfigMachine.Text + "' WHERE M_IDMAT = '" + NumMachine.Text + "'", connection);
    					commander.ExecuteNonQuery();
    				}
    ça peux pas fonctionner car les paramètre sont pas connu.

    merci d'avance!!

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

Discussions similaires

  1. Problème d'enregistrement dans une base de données
    Par mcfly37 dans le forum Hibernate
    Réponses: 1
    Dernier message: 08/07/2010, 17h41
  2. Réponses: 3
    Dernier message: 29/03/2008, 11h36
  3. problème d'insertion dans une base de données
    Par belmansour tidjani dans le forum JDBC
    Réponses: 7
    Dernier message: 18/01/2006, 22h13
  4. problème de recherche dans une base de donnée mysql
    Par Xini28 dans le forum SQL Procédural
    Réponses: 3
    Dernier message: 24/10/2005, 18h00
  5. problème de recherche dans une base de données
    Par bouzid_mehdi dans le forum Bases de données
    Réponses: 2
    Dernier message: 19/07/2005, 06h47

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