将值存储到.edmx表中

本文关键字:edmx 表中 存储 | 更新日期: 2023-09-27 18:14:21

我试图将一个int值存储到表中,但如果我将表数据类型从int32更改为字符串,则我将获得此消息http://postimg.org/image/cv1cc4jkf/full/,则我将不断获得消息"不能隐式地将字符串转换为int"有人能帮我解决这个问题吗?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();
    }

将值存储到.edmx表中

easyScoreLabel。Text是字符串。您需要将其转换为整型。

aMessage.highScoreEasy = Int.Parse(easyScoreLabel.Text);
aMessage.highScoreMedium = Int.Parse(mediumScoreLabel.Text);
aMessage.highScoreHard = Int.Parse(hardScoreLabel.Text);