using System.Web.Mvc; using MvcApplication2.Models; namespace MvcApplication2.Controllers { public class TestController : Controller { // // GET: /Test/ public void FillDataInTest() { Test test = new Test(); //Test is entity class SqlConnection objConn = new SqlConnection(@"server=DEV;Trusted_Connection=true;" + @"DATABASE=bank;User ID=BReader;Password=br123"); SqlCommand objCommand = new SqlCommand(@"Select Pub_bank_id,pub_bank_branch FROM parameter_online", objConn); SqlDataAdapter da = new SqlDataAdapter(objCommand); DataTable dt = new DataTable(); da.Fill(dt); for (int i = 0; i < dt.Rows.Count-1; i++) { test.Id =Convert.ToInt16(dt.Rows[i]["Pub_bank_id"]); test.Name = dt.Rows[i]["Pub_bank_id"].ToString(); } } public ActionResult Index() { try { TestDBContext db = new TestDBContext(); FillDataInTest(); ViewBag.Id = db.Tests.OrderBy(g => g.Id).ToList(); ViewBag.Name = db.Tests.OrderBy(a => a.Name).ToList(); var test = new Test(); return View(test); } catch (Exception e) { throw; } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)