Tuesday, October 30, 2018

ASP .net Razor v.3 Database Demo

I found a interesting post about this type of site here:
WebPagesRazor W3Schools

In MS VisualStudio 19
1) Create a new web site pick ASP.NET Empty Web Site
2) Add ASP.NET folder App_Data
3) Find the member.accdb in the unit on blackboard download it and and add it to App_data
4) Add a NewItem Web Page (Razor v3)
5) Add the connection string in the Web.config file.
  <connectionStrings>
    <add connectionString="Provider=Microsoft.ACE.OleDb.12.0;Data Source=|DataDirectory|member.accdb;" name="member" providerName="System.Data.OleDb">
  </add></connectionStrings>
6) Go into: Tools > NuGet Package Manager > Package Manager Console

And run the following command:
PM> Install-Package Microsoft.AspNet.WebPages.Data

then open the command prompt.

cd \Program Files (x86)\IIS Express

Then type the following command:
appcmd set config /section:system.webServer/directoryBrowse /enabled:true


7) Add this code (upto and including </body>) to your .cshtml file:
@using WebMatrix.Data;
@{
    var db = Database.Open("member");
    var selectQueryString = "SELECT * FROM memberTable ORDER BY LastName";
}
<html>
<body>
    <h1>
Paleo Scriptology Club Members</h1>
<table border="1" style="width: 100%;">
<tr>
            <th>Id</th>
            <th>LastName</th>
            <th>FirstName</th>
            <th>PhoneNumber</th>
        </tr>
@foreach (var row in db.Query(selectQueryString))
        {
<tr>
                <td>@row.StudentId</td>
                <td>@row.LastName</td>
                <td>@row.FirstName</td>
                <td>@row.PhoneNumber</td>
            </tr>
}
    </table>
</body>

Paleo Scriptology Club Members

@foreach (var row in db.Query(selectQueryString)) { }
Id LastName FirstName PhoneNumber
@row.StudentId @row.LastName @row.FirstName @row.PhoneNumber

</html>


Tuesday, October 16, 2018

Schedule change

Due to the school cancellation last week the mid term was (10/16/2018) at 3.
Thursday will be a lab.

I will cover chapter 15 next Tuesday.
The syllabus has been updated.