I get a list of IDs and amounts from an excel file (thousands of identifiers and corresponding amounts). Then I need to check the database to see if each identifier exists, and if it checks that the amount in the database is greater than or equal to the sum of the amount from the excel file.
The problem is that this select statement works more than 6,000 times, and the return values ββare time consuming. Even for 1/2 second, a piece will only take about an hour to make all the samples. (I usually don't get more than 5 max results back)
Is there a faster way to do this?
Is it possible to somehow transfer all IDs at once and just make 1 call and get a massive collection?
I tried using SqlDataReaders and SqlDataAdapters, but they seem to be pretty much the same (too long anyway)
A general idea of ββhow this works below
for (int i = 0; i < ID.Count; i++) { SqlCommand cmd = new SqlCommand("select Amount, Client, Pallet from table where ID = @ID and Amount > 0;", sqlCon); cmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = ID[i]; SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dataTable); da.Dispose(); }
source share