简体   繁体   中英

How to select a specific record from the table using Entity Framework?

I'm using Entity Framework to insert data in a database. Here is the table in my application http://prikachi.com/images/681/6555681G.jpg . What I want to do is when I click "Edit" to select the concrete record and to have the option to edit or update it the way it is done here http://www.codeproject.com/KB/library/363040/updatedelete.jpg . I'm using Visual Studio 2012, C#.

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        using (var db1 = new beeContext())
        {
            var Article = new Articles1()
            {
                Author = TextBox1.Text,
                Title=TextBox2.Text,
                Text=TextBox3.Text,
                Category=TextBox4.Text
            };

            db1.Articles1.Add(Article);
            db1.SaveChanges();
        }


        Label5.Visible = true;
        GridView1.DataBind();
    }


}

ASP.net I can't post a screenshot of the tables but there is nothing special - they don't even have relationships between - the whole application is just about filling the database.

您只需要修改从dbContext检索到的实体,然后调用dbContext.SaveChanges()

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM