连接数据库到Web应用程序时出错

时间:2014-07-14 04:55:49

标签: c# entity-framework

我是数据库驱动的Web应用程序的新手。当我尝试运行我的Web应用程序时,我收到了以下错误。

  

“错误1'FinalProject.projectDBEntities1'不包含   'messages'的定义,没有扩展方法'messages'接受   “FinalProject.projectDBEntities1”类型的第一个参数可以是   找到了(你是否错过了使用指令或汇编引用?)“

我以为我做的一切都是对的,但显然不是。请让我知道我做错了什么?这是我的代码: 这里也是我的数据库表的截图。 enter image description here

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace FinalProject 
{
public partial class WebForm1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        int totalScore = 0;
        String name = nameTextBox.Text;

        difficultyLabel.Visible = true;
        difficultyLabel.Text = "Difficulty Level: " + difficultyList.SelectedValue;
        learnLabel.Visible = false;
        enterNameLabel.Visible = false;
        nameTextBox.Visible = false;
        difficultyList.Visible = false;
        getStartedButton.Visible = false;
        chooseDifficultyLabel.Visible = false;
        //chosenLabel.Visible = true;
        changeDifficultyButton.Visible = true;
        scoreLabel.Visible = true;
        myScoresButton.Visible = true;
        startOverButton.Visible = true;
        welcomeUsernameLabel.Visible = true;
        welcomeUsernameLabel.Text = "Welcome " + nameTextBox.Text;
        scoreLabel.Text = "Score: " + totalScore;
    }

    protected void changeDifficultyButton_Click1(object sender, EventArgs e)
    {
        difficultyLabel.Visible = false;
        chooseDifficultyLabel.Visible = true;
        difficultyList.Visible = true;
        changeDifficultyButton.Visible = false;
        myScoresButton.Visible = false;
        startOverButton.Visible = false;
        getStartedButton.Visible = true;
        scoreLabel.Visible = false;
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void myScoresButton_Click(object sender, EventArgs e)
    {
        using (projectDBEntities1 dbcontext = new projectDBEntities1())
        {
            Message message = new Message();

            message.userName = nameTextBox.Text;
            message.highScoreEasy = "High Score on Easy: " + easyScoreLabel.Text;
            message.highScoreMedium = "High Score on Medium: " + mediumScoreLabel.Text;
            message.highScoreHard = "High Score on Hard: " + hardScoreLabel.Text; 
          dbcontext.messages.Add(message);
            dbcontext.SaveChanges();


   }

        GridView1.DataBind();
    }

    protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
    {

    }






}
}

0 个答案:

没有答案