Pretty minor but you don't need the `if (row_id == 0)` if (row_id++ > list_size) // Add the sublist to the result { result.Add(route_list); row_id = 0; route_list = new List<long>(); } Also it seem like you should also test for if (route_list.Count > 0 ) Connection, Command, and Reader behave the same with many DB so this is pretty portable. I think you can use conn.CreateCommand() Long is not required for `row_id` or `list_size`