Click here to Skip to main content
15,901,373 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi friends,
I have a table named "bon récéption " and which contains a foreign key Id_marche and in the interface of "bon récéption " I filled the combobox of the "libélllé marche"short market the problem is in button modify when I want to modify gives me this error
I will extract here my code and the error
thank you in advance


What I have tried:

Program.cmd.CommandText = "update bon_reception_marche set Id_marche = (select distinct Id_marche from marche where Libelle_marche = '" + comboBox3.Text + "') ,Designation_bon_reception ='" + textBox2.Text + "',Num_bon_reception='" + textBox1.Text + "',Date_reception ='" + dateTimePicker1.Value.Date + "',Unite ='" + textBox3.Text + "',Qte= " + Convert.ToDouble(textBox4.Text) + ",Prix_unitaire=" + Convert.ToDouble(textBox5.Text) + ",Montant =" + Convert.ToDouble(textBox6.Text) + ",TVA =" + Convert.ToDouble(comboBox1.Text) + ",MO ='" + textBox8.Text + "',OT ='" + textBox9.Text + "' where Id_bon_reception_marche ="+textBox7.Text;



erreur
Le format de la chaîne d'entrée est incorrect.
Posted
Updated 16-Mar-17 7:27am
Comments
Richard Deeming 16-Mar-17 15:41pm    
Program.cmd.CommandText = "update bon_reception_marche set Id_marche = (select distinct Id_marche from marche where Libelle_marche = @Libelle_marche), Designation_bon_reception = @Designation_bon_reception, Num_bon_reception = @Num_bon_reception, Date_reception = @Date_reception, Unite = @Unite, Qte = @Qte, Prix_unitaire = @Prix_unitaire, Montant = @Montant, TVA = @TVA, MO = @MO, OT = @OT where Id_bon_reception_marche = @Id_bon_reception_marche";

Program.cmd.Parameters.AddWithValue("@Libelle_marche", comboBox3.Text);
Program.cmd.Parameters.AddWithValue("@Designation_bon_reception", textBox2.Text);
Program.cmd.Parameters.AddWithValue("@Num_bon_reception", textBox1.Text);
Program.cmd.Parameters.AddWithValue("@Date_reception", dateTimePicker1.Value.Date);
Program.cmd.Parameters.AddWithValue("@Unite", textBox3.Text);
Program.cmd.Parameters.AddWithValue("@Qte", Convert.ToDouble(textBox4.Text));
Program.cmd.Parameters.AddWithValue("@Prix_unitaire", Convert.ToDouble(textBox5.Text));
Program.cmd.Parameters.AddWithValue("@Montant", Convert.ToDouble(textBox6.Text));
Program.cmd.Parameters.AddWithValue("@TVA", Convert.ToDouble(comboBox1.Text));
Program.cmd.Parameters.AddWithValue("@MO", textBox8.Text);
Program.cmd.Parameters.AddWithValue("@OT", textBox9.Text);
Program.cmd.Parameters.AddWithValue("@Id_bon_reception_marche", textBox7.Text);
Richard Deeming 16-Mar-17 15:43pm    
The error message translates as "The format of the input string is incorrect."

That means one of the values in one of the textboxes you're trying to convert to a number is not a valid number. You'll need to debug your code to find out which one.

Rather than using Convert.ToDouble, which throws an exception if the input is not valid, use Double.TryParse[^] and check the return value to ensure the user has entered a valid number.
Richard Deeming 16-Mar-17 15:44pm    
Also, do yourself a favour and give your controls meaningful names. You might remember what textBox42 represents now, but when you come back to your code in six months, you won't have a clue.
Member 13055644 16-Mar-17 15:50pm    
I found the error it is instead of choosing separate I have to write select top 1

And thank you very much for your help it's nice of you Sir

1 solution

The error message,The format of the input string is incorrect, is very clear. Your update command contains an error. You need to debug and figure out what is wrong.

Also you should never, and I mean never, use string concatenation to build SQL command. Search google for "parameterized queries sql server". Learn to love them and always use them.
 
Share this answer
 
Comments
Member 13055644 16-Mar-17 13:31pm    
Here it is
the second error
The subquery returned several values. This is not allowed when the subquery follows =,! =, <, <=,>,> = Or when it is used as an expression.
The instruction was stopped.
AnvilRanger 16-Mar-17 13:43pm    
And? You have a subquery that is returning more that one value, most likely your "select distinct Id_marche".

That is an issue you have to debug and fix. Not something I or anyone else can do for you. We do not have access to your computer or your server.
Member 13055644 16-Mar-17 13:46pm    
You do not have to give me an answer I asked a question to the people who will help me without telling me it's blabla
And be modest a little one day you can be in the same case as me
AnvilRanger 16-Mar-17 14:18pm    
In your reply to my answer you did not even ask a question. You just pasted another error message. Was it just for detail or did you want help with that error?

Looking at you questions and comments most of them are just short "how do I do this" questions where you show not code and less effort. That just shows to the people on this site that you are not willing to at least put forth some effort in asking a question. You are just looking for a canned answer that works without you putting forth any thought or effect. This is very rude because the people on this site do this for free.
Member 13055644 16-Mar-17 14:35pm    
First of all in this site there are people who asked me to post the script and to post the error it is for that I did like this and twoly the error that I posted the second one in Execution courses both for the service "format .." and for the question of the second question I asked if you are satisfied with my problem it is well otherwise not worth saying T'as dit forward Mr

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900