Using EntityDataSource control in ASP.net:
In this article I'm trying to explain how to work with EntityDataSource control for displaying database data to our DataControls. During this process we can able to learn how to configure EntityDataSource control and how to connect with DataControl. This is very simple to communicate with our Database.
Follow below steps to configure EntityDataSource control in our Application.
Right click on Project folder and then add new item option then choose ADO.NET Entity Data Model and then give a name for that.
Then click on Add button for adding .edmx file into our project.
While adding EDM a new window will appear like a confirmation message with “yes/ No/ Cancel" options when you click “yes" a new window will appear for configuring EDM Object.
Select the Generate from Database option in the wizard and then click the next button.
After clicking the Next button a new window will appear for connecting the Data Connection purpose, see the below screen shot.
Provide Entity name for that and then click on Next button then it's fetch database objects information like tables, views, stored procedures. Then choose your object and then click on Finish button. In the below example I just choose Table name as “tblEmployee".
After finish that configuration a new model has been created under App_Code folder. Refer below screen shot.
Now the time to implement the application using Entity Data Model control. Just create a page with the name EntityDataSource.aspx. and drag & drop EntityDataSource object available under DataControls tab.
Now the time to configure with Entity Data Source, just click on the smart tag and then choose Data Source option then choose Entity Data Source object. Then a new window will appear for configure the Entity Data Source object. Choose the Entity object name available under Named Connection dropdown then click on Next button.
Its redirect to new window there you can choose Entity table name and choose columns to include in that result display time and then click on Finish button.
Now, configuration Entity Data Model has been completed now the time to display the result into DataControls. Simply drag&drop gridview control to the design page and then click on smart tag then choose Data Source object as Entity Data Model then see the gridview control design.
Just see the source code of gridview after configure with Entity Data Model.
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
Select="it.[Emp_Name], it.[Emp_job], it.[Emp_Dep]">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
<asp:BoundField DataField="Emp_Name" HeaderText="Emp_Name" ReadOnly="True"
<asp:BoundField DataField="Emp_job" HeaderText="Emp_job" ReadOnly="True"
<asp:BoundField DataField="Emp_Dep" HeaderText="Emp_Dep" ReadOnly="True"
Now, it's a time to check the output just Press F5 on the key board and then see the output.
I hope this article will help you those who are looking for the same and those who are new to implement EntityDataSource control in your applications.
This is Naveen, I completed my MCA and I have around 3 years of experience in ASP.net while implement Web Applications. For past 3 years I learn no.of Technologies while implement my applications apart from that I try to learn new technologies and I try to implement that while implement my project.