Entity framework & Model class

Example to display the data in mvc with out using entity frame work(With out using model class)

Create a new mvc2 application 2Add a new view page in home folder(sample)2Go to home controller.cs2Include the following the namespace


Using system.data;

Using system.data.sqlclient;


2create the an action with name


2write the following code


Public Action Result Sample ()


Sql connection  con = new sql connection (“”);

String s= “select * from emp details “;

Sql data adapter da = new sql data adapter (s, con);

Data set ds = new data set ();

Da. Fill (ds, ‘x’);

List <data row> r = new list <data row> ();

For each (data row . x in ds. Tables [0].rows)

R.add ();

View data [“R”] = R;

Return view ();



2Go to sample view

2Write the following code

<% @ Import  name space = ‘system.data’ % >


<h2>Satya technologies  </h2>


<% HTML Begin Form ();%>

<table border = ‘2’ align = ‘center’ >


<th>EMP id </th> <th> E NAME </th><th>E sal </th>


<% for each (var x in (1 enumerable  <Data row> view data [‘R’])  I %)>


<td><% : HTML. Encode (x [0]%)></td>

<td><% : HTML. Encode (x [1]%)></td>

<td><% : HTML. Encode (x [2]%)></td>


<% } %>


<% HTML. End form (); %>