[英]storing value into .edmx table
I'm trying to store a value that is an int into a table, but I keep getting the message "cannot implicitly convert string to int" if I change the table datatype from int32 to string then I get this message http://postimg.org/image/cv1cc4jkf/full/ Can anyone help me resolve this issue? 我正在尝试将int的值存储到表中,但是如果我将表数据类型从int32更改为string,那么我会不断收到消息“无法将字符串隐式转换为int”,然后收到此消息http:// postimg .org / image / cv1cc4jkf / full /谁能帮我解决这个问题? easyScoreLabel, mediumScoreLabel, and highScoreLabel are labels I dragged onto the web application from the toolbox.
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();
}
easyScoreLabel.Text is the string. easyScoreLabel.Text是字符串。 You need to convert it to the int.
您需要将其转换为int。
aMessage.highScoreEasy = Int.Parse(easyScoreLabel.Text);
aMessage.highScoreMedium = Int.Parse(mediumScoreLabel.Text);
aMessage.highScoreHard = Int.Parse(hardScoreLabel.Text);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.