For the connection and so forth open the .csproj file by double clicking it, add the following package reference for System.Data.SqlClient
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<LangVersion>9.0</LangVersion>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
</ItemGroup>
</Project>
NuGet package or the newer package.
About row number, there is no built in feature other than ROW_NUMBER
Numbers the output of a result set. More specifically, returns the sequential number of a row within a partition of a result set, starting at 1 for the first row in each partition.
Sample
SELECT ROW_NUMBER() OVER(
ORDER BY CustomerIdentifier) AS Number,
CompanyName
FROM Customers
WHERE CustomerIdentifier > 4;
Now there is a half baked method I can present but first need to know a) is this a single user database? b) how many records?