Try using Dapper, the following example, no need to open the connection, Dapper opens and closes as needed
public static List<App_Users> GetAll()
{
using SqlConnection cn = new("TODO");
return cn.Query<App_Users>("SELECT * FROM [dbo].[App_Users]";).ToList();
}
Edit
If stuck on not using Dapper here is an example and note there is zero reason for static properties.
Notes, using GetInt32, GetString etc has better performance than GetFieldValue which has to resolve the column name while the former does not.
public class Customers
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
internal class DataOperations
{
public static async Task<List<Customers>> CustomersList()
{
List<Customers> list = new List<Customers>();
var statement = "SELECT Id,FirstName,LastName FROM dbo.Customers;";
await using var cn = new SqlConnection("TODO");
await using var cmd = new SqlCommand { Connection = cn, CommandText = statement };
await cn.OpenAsync();
await using var reader = await cmd.ExecuteReaderAsync();
while (reader.Read())
{
list.Add(new Customers() { Id = reader.GetInt32(0), FirstName = reader.GetString(1), LastName = reader.GetString(2) });
}
return list;
}
}