Table Splitting Insert Data

Introduction

This article shows how to do table splitting and insert 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 constraint


Webform1.aspx

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TableSplitting_InsertData.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="Insert" 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 TableSplitting_InsertData  
  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.             using (var context = new EmployeeDBEntities())  
  20.             {  
  21.                 var employee = new Employee  
  22.                 {  
  23.                     FirstName = "Steve",  
  24.                     LastName = "Robin"  
  25.                 };  
  26.   
  27.                 employee.EmployeeDetail = new EmployeeDetails()  
  28.                 {  
  29.                     Phone = "122443",  
  30.                     Email = "[email protected]"  
  31.                 };  
  32.   
  33.                 context.Employees.Add(employee);  
  34.                 context.SaveChanges();  
  35.             }  
  36.         }  
  37.     }  
  38. }

The following is the output of the application:


 

Summary

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


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