Create a new MVC2 application with the name “examples”; Go to solution explorer
Select the models folder
Click with RM button
Click on add
Click on new item
Select data option from visual C# in installed template
S elect entity data model
Type the EDM name (employee.EOMX)
Click on add
Select the option generate from data base
Click on next
Click on new connection
Type the server name (“dot net” or satya)
Activate the radio button
Use SQL authentication
--> Type username (“Sa”);
Type password (“ABC”);
Select the D/B as employee
Click on ok
Active the radio button --> yes includes the sensitive data in the connection string
Connection string name you find as employee entity
Click on next This will retrieve complete D/B objects and
From select emp details table
Click on finish
The model for data is ready
Learn the core features of ASP.NET Training and become master with our expertise tutorials.
Creation action method in control class
Go to home controller.cs file
Write the following code Using examples models; name space Public action result sample data () { Employee entities.obj=new employee entities (); View data [“Emp”] = obj.Emp details to list(); Return views (); } Creating view: Go to home folder;
Add new view page (sample data)
Write the following code <%@ import name space = “examples.models”%> <body> <h1>welcome to satya</h1> <div> <table align = “center” border = “2”> <tr> <th>Emp id </th><th>Ename</th><th>Designation</th><th>DOJ</th><th>salary</th><th>Deptno</th> </tr> <% for each (var x in (Enumerable<Emp class detail>) view data [“Emp”] { // C# code %> <tr> <td><%=HTML.Encode(x.Emp Id)%></td> <td><%=HTML.Encode(x.Ename)%></td> <td><%=HTML.Encode(x.designation)%></td> <td><%=HTML.Encode(DOJ)%></td> // MVC code ‘ ‘ </tr> <%}%> //C# code </table> </div> </body> Run the application and check
You liked the article?
Like : 0
Vote for difficulty
Current difficulty (Avg): Medium
1/15
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.
Stay Updated
Get stories of change makers and innovators from the startup ecosystem in your inbox