Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

How to update data using entity framework 6.0?

$
0
0

hello

am new in entity framework 6.0 concept

i want to update the data in entity framework 6.0 by usingado.net i already provide table name in the coding namedmann please apply the updation operation in normal way and execute this code based on the concept i used in the  insertion operation ?

please apply this operation on update button

Here is my code

cs

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

namespace WebApplication14
{
public partial class WebForm63 : System.Web.UI.Page
{

// mann mode = new mann();


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)

Clear();

}

void Clear()
{
tb_benefited.Text = tb_allowance.Text = "";
Button1.Text = "save";
}

protected void Button1_Click(object sender, EventArgs e)
{
//mode.benefited_leaves1 = tb_benefited.Text.Trim();
//mode.basic_allowance1 = tb_allowance.Text.Trim();

using (hospitalEntities ctx = new hospitalEntities())
{
// db1.manns.Add(mode);
// db1.SaveChanges();

ctx.manns.Add(new mann()
{
benefited_leaves1 = tb_benefited.Text,
basic_allowance1 = tb_allowance.Text

});

ctx.SaveChanges();

Clear();

}

}

}
}

aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm63.aspx.cs" Inherits="WebApplication14.WebForm63" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="tb_benefited" runat="server" ></asp:TextBox>
<asp:TextBox ID="tb_allowance" runat="server" ></asp:TextBox>

<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

<asp:Button ID="Button2" runat="server" Text="Update"  />


<asp:GridView runat="server" ID="Gv2" CellPadding="4" ForeColor="#333333" GridLines="both" AutoGenerateColumns="false" Width="90%" AllowPaging="true" PageSize="10">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="benefited_leaves1" HeaderText="Benefited Leaves" />
<asp:BoundField DataField="basic_allowance1" HeaderText="Basic Allowance" />

</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>

</form>
</body>
</html>


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>