Question :
I want to populate a grid as data is made available.
If you run a really large sql query in SQL Management Studio the results window starts to populate with rows as they are made ready (I effectively want to mimick this), however at the momoent when I run SQlExecDirect() I have to wait untill all rows have been calculated.
The following code is an example from Microsoft about Asynchronously doing an SQLExecDirect() Asynchronously
SQLHSTMT hstmt1;
SQLRETURN rc;
// Specify that the statement is to be executed asynchronously.
SQLSetStmtAttr(hstmt1, SQL_ATTR_ASYNC_ENABLE, SQL_ASYNC_ENABLE_ON, 0);
// Execute a SELECT statement asynchronously.
while ((rc=SQLExecDirect(hstmt1,"SELECT * FROM Orders",SQL_NTS))==SQL_STILL_EXECUTING) {
// While the statement is still executing, do something else.
// Do not use hstmt1, because it is being used asynchronously.
}
// When the statement has finished executing, retrieve the results.
Does anyone know if it is possible or how it is possible to Asynchronously call SQLFetch() Asynchronously and retrieve each row as it is made available?
Answer :
I don’t think async execution will accomplish what you want. SQL Server returns results to the client as they become available if you’ve specified a fast-forward ODBC cursor type.
Separately, displaying partial results in a GUI interface while the query is still running may require special programming techniques. That’s not really a database problem so StackOverflow would be a better forum if you have additional questions about that.