MySQL Forums
Forum List  »  General

Help with Reading data into a table
Posted by: Joseph fisher
Date: March 24, 2023 06:50AM

Hello all, I am trying to connect a sql database we use here at work for our ERP system to display some data on some TV's out on the production floor.

this is my first ever attempt playing with, Razor Pages etc.

last time I played with HTML even was in like 2014. I have made some apps in C# in recent years but nothing to write home about.

I am not receiving any errors, my page is displaying but the table i am trying to put the data into is left empty.

I don't see how to upload images to my post here on the forum to show my code, or a way to add code snippets, however my code is rather short so ill post what i have.

using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Data.SqlClient;

namespace CEMDataHub.Pages
public class ActiveJobsModel : PageModel
public List<TransactionData> transList = new List<TransactionData>();
public void OnGet()
string connectionString = "Data Source=jbserver\\jbsql;Initial Catalog=PRODUCTION;Persist Security Info=True;User ID=CEM;Password=***";
using (SqlConnection connection = new SqlConnection(connectionString))
string sql = "SELECT * FROM Transaction_Data;";
using (SqlCommand command = new SqlCommand(sql , connection))
using (SqlDataReader reader = command.ExecuteReader())
while (reader.Read())
TransactionData transaction = new TransactionData();
transaction.Id = reader.GetString(0);
transaction.Employee = reader.GetString(1);
transaction.WorkDate = reader.GetString(2);
transaction.TransactionStart = reader.GetString(3);
transaction.TransactionEnd = reader.GetString(4);
transaction.Job = reader.GetString(5);
transaction.Quantity = reader.GetString(6);
transaction.PO = reader.GetString(7);
transaction.LastUpdated = reader.GetString(8);

catch(Exception ex)



public class TransactionData
public string Id;
public string Employee;
public string WorkDate;
public string TransactionStart;
public string TransactionEnd;
public string Job;
public string Quantity;
public string PO;
public string LastUpdated;


next file
@model CEMDataHub.Pages.ActiveJobsModel
<br />
<h2>Active Transactions</h2>
<table class="table">
<th>Transaction Start</th>
<th>Job #</th>
@foreach (var transaction in Model.transList)

Options: ReplyQuote

Written By
Help with Reading data into a table
March 24, 2023 06:50AM

Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.