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 listClients = new List();
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

Abhishek YadavPosted Mar 6, 2024, 5:43 AM
Please refer to this article, it will help you out,
click here
Jignesh KumarPosted Mar 5, 2024, 4:07 AM
First of all, you are returning Void means that the method not returning any value.
And this method you need to call in your controller,
Please refer to this article, it will help you out,
https://www.c-sharpcorner.com/article/crud-operations-in-asp-net-core-mvc-net-5-0/