0

I have a problem with inserting values from a SQL table (pgadmin) to a web application. If I check my table in pgadmin, all is ok:

enter image description here

But if I push it into application on Azure, it returns only:

enter image description here

I don't know where the problem is.

display.data.razor:

@page "/displaydata"
@using WebApplication1.Data;
@using WebApplication1.Services;
@inherits OwningComponentBase<DataService>

<h1>Display data</h1>

<table border="1">
    <tr>
        <th>
            id
        </th>
        <th>
            Nazov IMG
        </th>
        <th>
            label
        </th>
    </tr>

    @foreach (WebApplication1.Data.Dataset item in sc)
    {
        <tr>
            <td>@item.relid</td>
            <td>@item.name</td>
            <td>@item.label</td>
        </tr>
    }

</table>

@code {
    public System.Collections.Generic.IList<Dataset> sc;

    protected override void OnInitialized()
    {
        sc = Service.displaydata();
        foreach (var item in sc)
        {
            Console.Write(@item.relid + " " + @item.label);
        }
}
}

Result of Console.Write(@item.relid + " " + @item.label):

2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)2 "Gold(99.64134)

DataService:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApplication1.Data;
namespace WebApplication1.Services
{
    public class DataService
    {
        protected readonly ApplicationDbContext _dbcontext;
        public DataService(ApplicationDbContext _db)
        {
            _dbcontext = _db;
        }
        public List<Dataset> displaydata()
        {
            return _dbcontext.results.ToList();
        }
    }
}

Data:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace WebApplication1.Data
{
    public class ApplicationDbContext : DbContext
    {
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
        {
        }
        public DbSet<Dataset> results { get; set; }
    }
}
2
  • Can you check the data source of sc when debugging? Or let us look at the query statement of your method at runtime. Commented May 6, 2021 at 13:45
  • I edited it, maybe now ? @JasonPan Commented May 6, 2021 at 18:27

1 Answer 1

1

Please follow my suggestions to troubleshoot

  1. First make sure that when running locally, the data is displayed in the foreach is correct.

  2. Log in to the scm website, or click on the App service editor in the portal, and check the web.config file. Or check the Connection strings in the Configuration.

    enter image description here

    The difference:

    If it is set in Connection strings, the database connection string in web.config will be overwritten. If not, then the web program will connect according to the string in web.config.

    enter image description here

  3. According to the string, use the SSMS tool to find the database and check whether the data is consistent with the error data displayed on the page.

  4. If the data displayed locally is incorrect in the first step, it is recommended that you create a new demo code and upload it to github so that we can perform local debugging. (Be careful to hide your confidential information)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.