簡體   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