I have a list of values of type string, I am currently looping over this and using it in the "WHERE" of many 1000's of SQL queries, I was wondering if I should run one query and do the filtering in the resulting datatable.
I have already implemented this using the multiple query method, and didn't notice any performance issues until the selection criteria grew into the 10's of thousands. I have tested with the StopWatch class and it looks like 95% of the time per loop is taken doing the SQL query, sum total of the table size on disk is < 50MB which would lead to a higher memory cost.
SQL is of the form:
SELECT col1, col2, col3 FROM table1 WHERE col4 = @criteria
Methods I have seen for the filtering of datatables come mostly from this post How I can filter a Datatable?
DataView dv = new DataView(dataTable);
dv.RowFilter = "query"; //query = String.Format("col4 = {0}", criteria)
DataTable dataTableFiltered = dataTable.AsEnumerable()
.Where(row => row.Field<String>("col4") == criteria)
.CopyToDataTable();
dataTable.select("query").CopyToDataTable()
Two part question really, should I convert to filtering in the datatable method, and if so which method would probably work fast enough?
Once the data is acquired, it is written to a text file structured like this:
@Criteria1
Values
@Criteria2
Values
Values
Values
@Criteria3
...