Display data using Razor syntax

Ratings:
(4)
Views:0
Banner-Img
  • Share this blog:

Example to Display data of a table using Razor syntax

Create  a new view page  using with Razor engine

         

Write the following code  

@ using system Data;
@using system Data.Sqlclient;
@ { layout = null ;
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’);
}
<! Doctype html>
<html>
<head>
<title> Sample 1 </title>
</head>
<body>
<h2>Satya tech </h2>
<div>
<form action = “” Method = “Post”>
<table border = “2” align = ‘center’>
<tr>
<th>EMP id </th> <th> E name </th> <th> E sal </th>
</tr>
@ foreach (Data row R in ds. Tables [0]. Rows)
{
<tr>
<td>@ R[0]</td> <td>@ R[1]</td><td>@ R[2]</td>
</tr>
</table>
</div>
</body>
</html>

Create new view page with the name (Samples)

Learn the core features of ASP.NET Training and become master with our expertise tutorials.

14   Write the following code

@using system. Data;
@using system. Data. Sqlclient;
@ { layout = null;
Var r = “”;
If (is post)
{
String s = “insert in to EMP Values  (”+ Request [“txt EMP id”] + “,”+Request [“txt E name”] “+”Request [txt E Sal]” +);
SQL connection = new sql connection (“”);
SQL command cmd = new dql command (s, con)
Con.open ();
Int i = cmd. Execute non query ();
Con. Close ();
R = I +”Record s inserted”
}
}
<body>
<h2>satya  technologies </h2>
<div>
<form action = ‘’ method = ‘post’>
<table border = ‘2’ align = ‘center’>
<tr>
<td>Enter EMP id </td> <td> <input type = ‘text’ name = ‘txt emp id’> </td>
</tr>
<tr>
<td>Enter E name </td> <td> <input type = ‘text’ name = ‘txt e name’> </td>
</tr>
<tr>
<td>Enter EMP Salary </td> <td> <input type = ‘text’ name = ‘txt emp  salary’> </td>
</tr>
<tr>
<td> @ R </td>  <td> <input type  = “submit ”  name = ‘B1 value = ‘’Insert’/>  </td>
</tr>
</table>
<tr>
<td>Enter Emp salary </td> <td> <Input type= “test” name= “txt emp sal”> </td>
 </tr>
<td> @</td><td><input type = “submit”name =”Bi”,value =”insert”></td>
</tr>
</table>

You liked the article?

Like : 0

Vote for difficulty

Current difficulty (Avg): Medium

Recommended Courses

1/15

About Author
Authorlogo
Name
TekSlate
Author Bio

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