4 Replies - 1565 Views - Last Post: 09 July 2012 - 01:12 PM Rate Topic: -----

#1 rbflowers  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 48
  • Joined: 10-February 12

pull data from database into a table visual studio

Posted 09 July 2012 - 12:33 PM

I'm putting together a dashboard and was told to use mvc3.

I created a .mdf database in visual studio and want to pull the data into a table, but don't know how to do that.

I have a few .cshtml files where I need the data to go.

I tried:

@{
ViewBag.Title = "test";

var db = System.Data.Entity.Database.Open("L1DB.mdf");
var grid = new WebGrid(db.Query("SELECT * FROM MetricOwner"));
}

but the

.Open() part returns an error.

I've never done anything like this before, so I'm completely lost.

Is This A Good Question/Topic? 0
  • +

Replies To: pull data from database into a table visual studio

#2 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 498
  • View blog
  • Posts: 3,317
  • Joined: 12-January 10

Re: pull data from database into a table visual studio

Posted 09 July 2012 - 12:34 PM

what error does it give?
Was This Post Helpful? 0
  • +
  • -

#3 rbflowers  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 48
  • Joined: 10-February 12

Re: pull data from database into a table visual studio

Posted 09 July 2012 - 12:40 PM

System.Data.Entity.Database. does not contain a definition for Open
Was This Post Helpful? 0
  • +
  • -

#4 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 498
  • View blog
  • Posts: 3,317
  • Joined: 12-January 10

Re: pull data from database into a table visual studio

Posted 09 July 2012 - 12:50 PM

do you have code behind?
Was This Post Helpful? 0
  • +
  • -

#5 rbflowers  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 48
  • Joined: 10-February 12

Re: pull data from database into a table visual studio

Posted 09 July 2012 - 01:12 PM

All I have now is:

test.cshtml:
@{
    ViewBag.Title = "test";


    var db = System.Data.Entity.Database.Open("L1DB.mdf");
    var grid = new WebGrid(db.Query("SELECT * FROM MetricOwner"));
}

<script type="text/javascript">
    window.onload = runChart(); 
</script>


    <div id="oveA">
        <div id="boxTitle">title</div>
        
        <div class="monthlyGauge">
        </div>
        <div class="excelChart" id="EA">
            <table>
                <tr>
                    <th id = "titles"></th>
                    <th id = "titles"></th>
                    <th id = "titles"></th>
                    <th id = "titles"></th>
                    <th id = "titles"></th>
                    <th id = "titles"></th>
                    <th id = "titles"></th>
                </tr>
                <tr>
                    <td id = "content"></td>
                    <td id = "content"></td>
                    <td id = "content"></td>
                    <td id = "content"></td>
                    <td id = "content"></td>
                    <td id = "content"></td>
                    <td id = "content"> </td>
                </tr>
            </table>
            <br /><br />
            <ul>
                <li><a href="#">Link1</a></li>
                <li><a href="#">Link2</a></li>
            </ul>
        </div><br /><br /><br />
        <div class="YTD" id="YTDA">ytd gauge</div>
        <div class="Other" id="run"></div>
        
    </div>


I will need the info from the DB to go in the <td> elements
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1