ASP.NET(vb.net) & EntityDataSource - asp:EntityDataSource - The EntityDataSource represents an Entity Data Model (EDM) to data-bound controls in an ASP.NET application.
ShotDev Focus:
- ASP.NET(vb.net) & EntityDataSource - asp:EntityDataSource
Tag Control :
<asp:EntityDataSource ID="EntityDataSource1" runat="server"></asp:EntityDataSource>
On current project Right Click -> Add New Item…
Add New Item ADO.NET Entity Data Model.
Click Yes . for Move code to folder ‘App_Code’
Entity Data Model Wizard -> Generate form database. -> Next
Choose your data connection or create New Connection…
If new create new connection. Choose Microsoft SQL Server
Connection Properties (Server name,Lo on to the server , Connect to a database)
Click Next > for go to next step.
Choose your database object. (Entity Data Model)
Entity Data Model From creating.
Drag EntityDataSource Control to ASP.NET Web Form. On EntityDataSource Tasks -> Configure Data Source…
Configure ObjectContext Select Name Connection form Entities Data Source.
Configure Data Selection. (EntitySetName m EntityTypeFilter)
Drag GridView Control to ASP.NET Web Form and Choose Data Source EntityDataSource (Enable : Paging, Sorting, Editing, Deleting, Selection)
Example
EntityDataSource.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="EntityDataSource.aspx.vb" Inherits="EntityDataSource" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>ShotDev.Com Tutorial</title> </head> <body> <form id="form1" runat="server"> <div> <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=mydatabaseEntities" DefaultContainerName="mydatabaseEntities" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" EntitySetName="customers"> </asp:EntityDataSource> <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="CustomerID" DataSourceID="EntityDataSource1"> <Columns> <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" /> <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" /> <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" /> <asp:BoundField DataField="CountryCode" HeaderText="CountryCode" SortExpression="CountryCode" /> <asp:BoundField DataField="Budget" HeaderText="Budget" SortExpression="Budget" /> <asp:BoundField DataField="Used" HeaderText="Used" SortExpression="Used" /> </Columns> </asp:GridView> </div> </form> </body> </html>
EntityDataSource.aspx.vb
Partial Class _Default Inherits System.Web.UI.Page End ClassPartial Class EntityDataSource Inherits System.Web.UI.Page End Class
Screenshot