Quote:i want to compare the values of dt_data to my database and display it on another datagridview which is dt_sample
I believe your requirement is just to query the data from database and show it in the grid, no comparison needed—apart from a
Instead of a loop—which is awfully bad for performance in this case—I would recommend that you use SQL
construct. That would be like this:
SELECT * FROM [Customer] WHERE [meter_num] IN (@parameters);
Although this is a bit difficult to code in .NET based languages, see this thread, c# - How to pass sqlparameter to IN()? - Stack Overflow
]. But the overall outcome of this will be great.
IN (Transact-SQL) - SQL Server | Microsoft Docs
Your database engine will be returning the results based on the
condition, and you will have to create just a single grid to render the output. You can even try to create a stored procedure that can help you with this.
But if you still want to continue with that approach, you should first read all the data (keep appending to the list), and then use a single list of records to support the
field. This will also improve the performance, due to lesser number of memory allocations.