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? easyScoreLabel, mediumScoreLabel, and highScoreLabel are labels I dragged onto the web application from the toolbox.
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. You need to convert it to the int.
aMessage.highScoreEasy = Int.Parse(easyScoreLabel.Text);
aMessage.highScoreMedium = Int.Parse(mediumScoreLabel.Text);
aMessage.highScoreHard = Int.Parse(hardScoreLabel.Text);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.