繁体   English   中英

将值存储到.edmx表中

[英]storing value into .edmx table

我正在尝试将int的值存储到表中,但是如果我将表数据类型从int32更改为string,那么我会不断收到消息“无法将字符串隐式转换为int”,然后收到此消息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();
    }

easyScoreLabel.Text是字符串。 您需要将其转换为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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM