How should we know?
We have no idea what your
DataTableToJSONWithStringBuilder
method is doing - other than the broad outline the method name provides - nor any idea exactly which line is causing the problem.
So, its going to be up to you.
Put a breakpoint on the first line in that code, and run your app through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.
Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
Quote:
Hi,
I am also thinking the same. But I am not a sql expert. How I can fetch it in batches like first 50k and then so on..
Depends on your SQL server version.
The old way is to use ORDER BY with a ROW_NUMBER:
SELECT MyColumns
FROM (SELECT MyClolumns, ROW_NUMBER() OVER (ORDER BY UniqueKeyColumn) AS RowNum FROM MyTable) s
WHERE s.RowNum BETWEEN @StartRow AND @EndRow
This works from SQL 2005 onwards.
SQL 2012 introduced OFFSET-FETCH:
SELECT MyColumns FROM MyTable ORDER BY UniqueKeyColumn OFFSET @STARTROW ROWS FETCH NEXT @ROWSCOUNT ROWS ONLY