Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am trying to see the contents of a online MS SQL table called "test".

The connectionstring is working and named "DataContext".

View1.cshtml
C#
@model IEnumerable<dbMVC.Models.test>

@{
    ViewBag.Title = "Home Page";
}

<h2>View1</h2>

@foreach (var item in Model)
{
    <h2>@item.idt @item.datetime  @item.col1 @item.col2 @item.col3</h2>
}


TestData.cs
C#
using dbMVC.Models;
using System.Data.Entity;

namespace dbMVC.Controllers
{
    public class TestDataController : Controller
    {
        //
        // GET: /TestData/

        private DataContext db = new DataContext();
        public ActionResult DataIndex()
        {
            var dataout = from test in db.Data1 select test;
            return View(dataout);
        }
    }
}


DataContext.cs
C#
using System.Data.Entity;
using dbMVC.Models;

namespace dbMVC.Models
{
    public class DataContext : DbContext
    {
        //enables CRUD
        public DbSet<test> Data1 { get; set; }
    }
}


Data.cs
C#
namespace dbMVC.Models
{
    public class test
    {
        public int idt { get; set; }
        public string datetime { get; set; }
        public string col1 { get; set; }
        public string col2 { get; set; }
        public string col3 { get; set; }
    }
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900