Avatar of Murray Brown
Murray Brown
Flag for United Kingdom of Great Britain and Northern Ireland asked on

ASP.net Razor page that pulls data from a SQL database

Hi


In an ASP.net Blazor project I want to add a new razor page that pulls data from an SQL table using a connection string. How do I alter the bottom part of the following code to rather pull data from an MS SQL Server database database? Also what type of page should I choose based on the image further down.

@page "/fetchdata"
@using Blazor1.Shared
@inject HttpClient Http <h1>Weather forecast</h1> <p>This component demonstrates fetching data from the server.</p> @if (forecasts == null) {     <p><em>Loading...</em></p> } else {     <table class="table">         <thead>             <tr>                 <th>Date</th>                 <th>Temp. (C)</th>                 <th>Temp. (F)</th>                 <th>Summary</th>             </tr>         </thead>         <tbody>             @foreach (var forecast in forecasts)             {                 <tr>                     <td>@forecast.Date.ToShortDateString()</td>                     <td>@forecast.TemperatureC</td>                     <td>@forecast.TemperatureF</td>                     <td>@forecast.Summary</td>                 </tr>             }         </tbody>     </table> } @code {     private WeatherForecast[] forecasts;     protected override async Task OnInitializedAsync()     {         forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("WeatherForecast");     } }

Open in new window




ASP.NETDatabases* RazorMicrosoft SQL Server

Avatar of undefined
Last Comment
Misha

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Misha

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61