public class HomeController : Controller { public static string con_str = @"Data Source=10.0.0.222;Initial Catalog=Student;User ID=IAdmin;Password=sql2008@"; public ActionResult Index() { return View(); } [HttpPost] public ActionResult ViewResult() { SqlConnection con = new SqlConnection(con_str); con.Open(); SqlCommand cmd = new SqlCommand("select * from Sturecord", con); SqlDataAdapter da = new SqlDataAdapter(cmd); //SqlDataReader Myreader = cmd.ExecuteReader(); DataTable dt = new DataTable(); da.Fill(dt); return View("Index", dt); } } }
@model System.Data.DataTable @using System.Data; <div id="queryResult"> <div> <table cellpadding="10" border="1"> <thead> <tr> @foreach (DataColumn col in Model.Columns) { <th>@col.ColumnName</th> } </tr> </thead> <tbody> @foreach (DataRow row in Model.Rows) { <tr> @foreach (DataColumn col in Model.Columns) { <td>@row[col.ColumnName]</td> } </tr> } </tbody>
@model System.Data.DataTable @using System.Data; @{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>Index</h2> @using(Html.BeginForm("ViewResult","home",FormMethod.Post)) { @Html.TextArea("txtquery"); @Html.TextBox("btnsubmit", "submit", new { type = "submit" }); } <div> @Html.RenderPartial("~/Views/Shared/_showOp.cshtml",dt) </div>
DataTable dt = new DataTable("dt");
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)