Create a new mvc2 application Add a new view page in home folder(sample)
Go to home controller.cs
Include the following the namespace
Using system.data; Using system.data.sqlclient;
create the an action with name
write 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 (); }
Go to sample view
Write the following code <% @ Import name space = ‘system.data’ % > <body> <h2>Satya technologies </h2> <div> <% HTML Begin Form ();%> <table border = ‘2’ align = ‘center’ > <tr> <th>EMP id </th> <th> E NAME </th><th>E sal </th> </tr> <% for each (var x in (1 enumerable <Data row> view data [‘R’]) I %)> <tr> <td><% : HTML. Encode (x [0]%)></td> <td><% : HTML. Encode (x [1]%)></td> <td><% : HTML. Encode (x [2]%)></td> </tr> <% } %> </table> <% HTML. End form (); %> </div> </body>
You liked the article?
Like: 0
Vote for difficulty
Current difficulty (Avg): Medium
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.