Table Splitting Select Data

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

SQL Server table structure


Create an ASP.Net Web Application as shown in the following screenshot.


Set Up Entity Framework


 
 
 
 

Cut columns from the Employee entity.


Paste them into the Employee details entity


Add an association between Employee and EmployeeDetails.


 
 

Referential constraints


Webform1.aspx

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TableSplitting_SelectData.WebForm1" %>  
  2. <!DOCTYPE html>  
  3. <html  
  4.     xmlns="http://www.w3.org/1999/xhtml">  
  5.     <head runat="server">  
  6.         <title></title>  
  7.     </head>  
  8.     <body>  
  9.         <form id="form1" runat="server">  
  10.             <div>  
  11.                 <asp:GridView ID="GridView1" runat="server" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None">  
  12.                     <AlternatingRowStyle BackColor="PaleGoldenrod"></AlternatingRowStyle>  
  13.                     <FooterStyle BackColor="Tan"></FooterStyle>  
  14.                     <HeaderStyle BackColor="Tan" Font-Bold="True"></HeaderStyle>  
  15.                     <PagerStyle HorizontalAlign="Center" BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"></PagerStyle>  
  16.                     <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite"></SelectedRowStyle>  
  17.                     <SortedAscendingCellStyle BackColor="#FAFAE7"></SortedAscendingCellStyle>  
  18.                     <SortedAscendingHeaderStyle BackColor="#DAC09E"></SortedAscendingHeaderStyle>  
  19.                     <SortedDescendingCellStyle BackColor="#E1DB9C"></SortedDescendingCellStyle>  
  20.                     <SortedDescendingHeaderStyle BackColor="#C2A47B"></SortedDescendingHeaderStyle>  
  21.                 </asp:GridView>  
  22.             </div>  
  23.         </form>  
  24.     </body>  
  25. </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. namespace TableSplitting_SelectData   
  8. {  
  9.     public partial class WebForm1: System.Web.UI.Page  
  10.     {  
  11.         EmployeeDBEntities objEmpEntities = new EmployeeDBEntities();  
  12.         protected void Page_Load(object sender, EventArgs e)   
  13.         {  
  14.             var query = from r in objEmpEntities.Employees.Include("EmployeeDetails")  
  15.             select new   
  16.             {  
  17.                 r.FirstName,  
  18.                 r.LastName,  
  19.                 r.EmployeeDetail.Phone,  
  20.                 r.EmployeeDetail.Email  
  21.             };  
  22.             GridView1.DataSource = query.ToList();  
  23.             GridView1.DataBind();  
  24.         }  
  25.     }  
  26. }  
The output of the application is as shown in the following screenshot.


Summary

In this article, we saw how to do table splitting and a select data operation.

Happy coding.


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