使用C#表单中的实体框架更新数据

时间:2017-05-22 06:13:23

标签: c# entity-framework

我是实体框架的初学者。我想通过使用实体框架C#更新数据,但始终出现此错误

  

未处理的类型' System.InvalidOperationException'发生在EntityFramework.dll

我正在使用Visual Studio 2013

<uses-permission android:name="android.permission.WRITE_SETTINGS"/>

1 个答案:

答案 0 :(得分:0)

namespace Entity_FrameWork
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Beta_DatabaseEntities db = new Beta_DatabaseEntities();
        table1 tb = new table1();
        public int ID;
        public string Name;
        public int Salary;

        public void Entry()
        {
            ID = Convert.ToInt16(id.Text);
            Name = name.Text;
            //Salary = Convert.ToInt32(salary.Text);
            tb.Id = ID;
            tb.Name = Name;
            //tb.Salary = Salary;
        }

        private void update_Click(object sender, EventArgs e)
        {tb=db.Tables.where(x=>x.id==1).firstOrDefault();
            Entry();
            db.SaveChanges();
            MessageBox.Show("UPDATED");
        }
    }
}