Table Splitting Update Data

Introduction

This article shows how to do table splitting and update data operations.

SQL Server table structure


Create an ASP.Net Web Application as in the following:


Set up Entity Framework as in the following:


 
 
 
 

Cut columns from the employee entity as in the following:


Paste them into the EmployeeDetails entity as in the following:


Add an association between Employee and EmployeeDetails as in the following:


 
 

Referential constraints


Webform1.aspx

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Table_Splitting_Update_Data.WebForm1" %>  
  2.   
  3. <!DOCTYPE html>  
  4.   
  5. <html xmlns="http://www.w3.org/1999/xhtml">  
  6. <head runat="server">  
  7.     <title></title>  
  8. </head>  
  9. <body>  
  10.     <form id="form1" runat="server">  
  11.     <div>  
  12.         <asp:Button ID="Button1" runat="server" Text="Update" OnClick="Button1_Click" />  
  13.     </div>  
  14.     </form>  
  15. </body>  
  16. </html>

Webform1.aspx.cs

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7.   
  8. namespace Table_Splitting_Update_Data  
  9. {  
  10.     public partial class WebForm1 : System.Web.UI.Page  
  11.     {  
  12.         protected void Page_Load(object sender, EventArgs e)  
  13.         {  
  14.   
  15.         }  
  16.   
  17.         protected void Button1_Click(object sender, EventArgs e)  
  18.         {  
  19.             EmployeeDBEntities empContext = new EmployeeDBEntities();  
  20.             int empId = 1;  
  21.             var emp = empContext.Employees.Where(a => a.EmpId.Equals(empId)).SingleOrDefault();  
  22.             emp.FirstName = "Jonny";  
  23.             emp.EmployeeDetail.Email = "[email protected]";  
  24.             empContext.SaveChanges();  
  25.         }  
  26.     }  
  27. }

The following is the output of the application:


Before performing update operation:

 

After performing update operation:

 

Summary

In this article we saw how to do table splitting and update data operations.
Happy coding!


Similar Articles
MVC Corporation
MVC Corporation is consulting and IT services based company.