转换错误视觉工作室 [英] conversion error visual studio
问题描述
你好。
我在visual studio 2008上有2天的问题,我什么都不懂......
这是我的问题:
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);
其他行很好,带箭头的3行会出现此错误:
不能隐式地将类型'int'转换为'string'
为什么以及如何解决我的问题?谢谢
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
推荐答案
看起来你要来回转换东西,而不是写一些代码。现在有迹象显示初学者的主要谬误:尝试使用代表数据的字符串而不是数据本身。它确实无处可去。
并且您没有显示代码的相关部分。
在此case,I_Projet.id_projet
和I_Projet.id_devis
可能是字符串,并且您正在为它们分配整数。谁告诉你你可以这样做?
-SA
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
andI_Projet.id_devis
are probably strings, and you are assigning integers to them. Who told you that you could do it?
—SA
对于这三行掉线Convert.ToInt32。直接使用SelectedValue:
For these three lines drop Convert.ToInt32. Use SelectedValue directly:
I_Projet.id_typeprojet = DDL_TypeProj.SelectedValue;
I_Projet.id_projet = DDL_Projet.SelectedValue;
I_Projet.id_devis = DDL_Devis.SelectedValue;
如果您仍想保留相同的代码,那么只需编写.ToString();
之后的方法转换.ToInt32(DDL_Projet.SelectedValue)
例如Convert.ToInt32(DDL_Projet.SelectedValue).ToString();
为其他具有相同错误的行执行此操作
或者您可以将I_Projet.id_projet,I_Projet.id_devis,I_Projet.id_typeprojet数据类型更改为int
都可以工作
欢迎你
快乐编码
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
这篇关于转换错误视觉工作室的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!