我试图将一个int值存储到一个表中,但我不断收到消息"不能隐式地将字符串转换为int"如果我将表数据类型从int32更改为string然后我收到此消息http://postimg.org/image/cv1cc4jkf/full/ 任何人都可以帮我解决这个问题吗? easyScoreLabel,mediumScoreLabel和highScoreLabel是我从工具箱拖到Web应用程序上的标签。
protected void myScoresButton_Click(object sender, EventArgs e)
{
using (projectDBEntities1 dbcontext = new projectDBEntities1())
{
message aMessage = new message();
aMessage.userName = nameTextBox.Text;
aMessage.highScoreEasy = Int32.Parse(easyScoreLabel.Text);
aMessage.highScoreMedium = Int32.Parse(mediumScoreLabel.Text);
aMessage.highScoreHard = Int32.Parse(hardScoreLabel.Text);
dbcontext.messages.Add(aMessage);
dbcontext.SaveChanges();
}
GridView1.DataBind();
}
答案 0 :(得分:0)
easyScoreLabel.Text是字符串。您需要将其转换为int。
aMessage.highScoreEasy = Int.Parse(easyScoreLabel.Text);
aMessage.highScoreMedium = Int.Parse(mediumScoreLabel.Text);
aMessage.highScoreHard = Int.Parse(hardScoreLabel.Text);