There is a close question here: .NET DataTable skips rows in Load (DataReader)
I have an SQL query that returns 169 results. The result is as follows:
CustomerID Customer Name TerminalID Creation Date 1 First Customer 12345 2010-07-07 1 First Customer 12346 2010-07-07 1 First Customer 12347 2010-07-07 2 Second Customer 23456 2011-04-18
This result is correct.
I entered the request into a C # program and executed it as follows:
public DataTable getDataTableFromSql(FbCommand command) {
This code has been tested, and it is great for different SQL queries. But for the above query, the DataTable contains only 39 results and looks like this:
CustomerID Customer Name TerminalID Creation Date 1 First Customer 12347 2010-07-07 2 Second Customer 23456 2011-04-18
I distorted the code a bit and this is what I have learned so far: FbDataReader correctly retrieves the results from the database. If I just request a TerminalID , I get 169 results in a DataTable . If I ask for CustomerID , I get 39 results.
Conclusion: The line result.Load(sqlReader) groups the result for CustomerID and discards all other results, regardless of whether they can be grouped or not.
Why is this happening? How can I load the result of my query into a DataTable without "losing" any rows due to illogical grouping? And why in the DataTable group is the βresultβ in the first place?
Note. I also tried all three LoadOptions available for DataTables , all with the same result: only 39 results are loaded into the DataTable .
source share