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
@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
| Id | LastName | FirstName | PhoneNumber |
|---|---|---|---|
| @row.StudentId | @row.LastName | @row.FirstName | @row.PhoneNumber |
</html>
If you can not find WebMatrixData 1.0.0.0 (MSVC 2017 is such a case)
ReplyDeleteStart the PM: Tools->NuGet Package Manager
PM> Install-Package Microsoft.AspNet.WebHelpers
then
PM>Install-Package Microsoft.AspNet.WebPages.Data
In Visual Studio 2015, follow these steps:
ReplyDeleteGo into: Tools > NuGet Package Manager > Package Manager Console
And run the following command:
PM> Install-Package Microsoft.AspNet.WebPages.Data
Open the command prompt on your PC
Type the following command:
cd \Program Files (x86)\IIS Express
Then type the following command:
appcmd set config /section:system.webServer/directoryBrowse /enabled:true
If you get the following error:
ReplyDeleteACE.OLEDB.12.0 provider not registered on local machine
Run this:
https://www.microsoft.com/en-us/download/confirmation.aspx?id=13255