DoFileRowID and SortColAscending returns seem to be backwards.
Also you are invoking ExecuteReader but using it.
Example what it might be targeting one table rather than many. Note that in this example I'm using IConfiguration to read the connection string from appsettings.json which you can do or not and logging is done with SeriLog. Done in C#, .NET Core 7 class project.
using Microsoft.Data.Sqlite;
using Microsoft.Extensions.Configuration;
using Serilog;
namespace SqlLibrary.Models;
public class SomeTableOperations
{
private static IConfiguration? _configuration;
public static (bool, List<SomeTable> list) ReadSomeTable(SortOrder order)
{
List<SomeTable> list = new();
using SqliteConnection cn = new();
cn.ConnectionString = _configuration.GetValue<string>("ConnectionStrings:ApplicationConnection");
using SqliteCommand cmd = new();
cmd.Connection = cn;
var sort = order == SortOrder.Ascending ? "asc" : "desc";
cmd.CommandText = $"SELECT RowID,PIN,FirstName,LastName FROM SomeTable ORDER BY LastName {sort}";
try
{
cn.Open();
var reader = cmd.ExecuteReader();
while (reader.Read())
{
list.Add(new SomeTable()
{
RowID = reader.GetInt32(0),
PIN = reader.GetString(1),
FirstName = reader.GetString(2),
LastName = reader.GetString(3)
});
}
return (true, list);
}
catch (Exception localException)
{
Log.Error(localException, $"Failed to read data in {nameof(ReadSomeTable)}");
return (false, null);
}
}
}