I am trying to display every row from a database on a website with ASP.NET Core MVC, but I cannot find any source on how to do it.. This is what Ive tried to do but I got stuck:
public IActionResult Index()
{
connection.Open();
command.Connection = connection;
command.CommandText = "SELECT COUNT(*) FROM Users;";
var rows = Convert.ToInt32(command.ExecuteReader());
command.Dispose();
List<UserModel> users = new List<UserModel>();
for(int i = 0; i <= rows; i++)
{
users.Add(new UserModel(ID, "", ""));
}
command.CommandText = "SELECT * FROM Users";
dataReader = command.ExecuteReader();
return View();
}
My Database is structured like this: Id, Username, Password, PasswordHash, but I only want to display Username to begin with.
If you have any sources or ideas it would be very appriciated! Thanks beforehand!
Best Regards Max