Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello.

I have a problem for 2 days on visual studio 2008 and i don't understand anything...

here is my problem :

ClassProjet I_Projet = new ClassProjet();
int I_Retour = 0;
I_Projet.Num_Projet = VarNumproj.Text;
I_Projet.Description = TextBox1.Text;
==> I_Projet.id_typeprojet = Convert.ToInt32(DDL_TypeProj.SelectedValue);
I_Projet.id_statutprojet = Convert.ToInt32(DDL_Statut_Projet.SelectedValue);
I_Projet.id_client = Convert.ToInt32(DDL_Client.SelectedValue);
==> I_Projet.id_projet = Convert.ToInt32(DDL_Projet.SelectedValue);
==> I_Projet.id_devis = Convert.ToInt32(DDL_Devis.SelectedValue);

The other lines are good and the 3 with the arrows make this error :
Cannot implicitly convert type 'int' to 'string'

Why and how can I solve my problem? Thank you
Posted
Comments
amit29391 13-Jun-13 2:13am    
what is datatype of I_Projet.id_projet,I_Projet.id_devis and I_Projet.id_typeprojet
stephane1301 13-Jun-13 2:17am    
Thank you for reply. I am just an Intern and I am trying to make it work.. I don't understand why it work for I_Projet.statutprojet and not for I_Projet.typeprojet. It is copy-paste. Actually I must convert it in order to insert it into my database.

It looks that you are converting things back and forth, instead of writing some code. There are signs of on of the main fallacies of the beginners these days: trying to work with strings representing data instead of data itself. It really goes nowhere.

And you are not showing relevant part of your code.

In this case, I_Projet.id_projet and I_Projet.id_devis are probably strings, and you are assigning integers to them. Who told you that you could do it?

—SA
 
Share this answer
 
Comments
stephane1301 13-Jun-13 2:24am    
I just learned the language last week and I_Projet.id_statutprojet has the same datatype than the 3 that don't work.. if I am doing it wrong the 5 lines would have been wrong but only 3 are wrong.
Sergey Alexandrovich Kryukov 13-Jun-13 2:26am    
Look, dealing with such types is way too simple. Look how you defined those variables/members, their types. Read error message.
—SA
stephane1301 13-Jun-13 2:32am    
Thank you for the help i will try to see
Sergey Alexandrovich Kryukov 13-Jun-13 2:41am    
Sure. Don't forget to accept this answer formally (green button), as soon as you can see. :-)
—SA
Espen Harlinn 13-Jun-13 17:52pm    
5'ed!
For these three lines drop Convert.ToInt32. Use SelectedValue directly:

C#
I_Projet.id_typeprojet = DDL_TypeProj.SelectedValue;
I_Projet.id_projet = DDL_Projet.SelectedValue;
I_Projet.id_devis = DDL_Devis.SelectedValue;
 
Share this answer
 
Comments
stephane1301 13-Jun-13 2:31am    
Thank you for the help
Espen Harlinn 13-Jun-13 17:50pm    
5'ed!
If you still want to keep the same code then just write .ToString(); method after
Convert.ToInt32(DDL_Projet.SelectedValue)

eg Convert.ToInt32(DDL_Projet.SelectedValue).ToString();
do it for other lines with same error

or you can change I_Projet.id_projet, I_Projet.id_devis, I_Projet.id_typeprojet datatype to int
both will work

you are welcome
happy coding
 
Share this answer
 
v2
Comments
stephane1301 13-Jun-13 2:31am    
Thank you for the help

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