Not read data from database
In table porezi have data
My code
Table header have, table data no have, no error
Some help?
My code
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Data.SqlClient;
namespace MyStore.Pages.Porezi
{
public class IndexModel : PageModel
{
public List<ClientInfo> listClients = new List<ClientInfo>();
public void OnGet()
{
try
{
String connectionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=test;Integrated Security=True;Trust Server Certificate=True";
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
String sql = "SELECT * FROM porezi";
using (SqlCommand command = new SqlCommand(sql, connection))
{
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
ClientInfo clientInfo = new ClientInfo();
clientInfo.id = "" + reader.GetInt32(0);
clientInfo.redni_broj = reader.GetString(1);
clientInfo.naziv = reader.GetString(2);
clientInfo.procenat= "" + reader.GetString(3);
clientInfo.fiksna_vrednost = "" + reader.GetString(4);
clientInfo.oznaka = reader.GetString(5);
listClients.Add(clientInfo);
}
}
}
}
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.ToString());
}
}
public class ClientInfo
{
public String id;
public String redni_broj;
public String naziv;
public String procenat;
public String fiksna_vrednost;
public String oznaka;
}
}
}
REst of code
