DB Library for C

DB Library for C


Sets up the results of the next query.


RETCODE dbresults ( PDBPROCESS dbproc );



Is the DBPROCESS structure that is the handle for a particular workstation or Microsoft® SQL Server™ 2000 process. It contains all the information that DB-Library uses to manage communications and data between the workstation and SQL Server.


SUCCEED, FAIL, NO_MORE_RESULTS, or NO_MORE_RPC_RESULTS. The most common reason for failing is a NULL or inactive dbproc. NO_MORE_RPC_RESULTS is returned when stored procedure return information is available from one stored procedure in a batch of multiple stored procedures. NO_MORE_RESULTS is returned if there are no more results to be processed.

Note  This function is one of the four that do not return control to the application until the server sends the required response. The application can be blocked for a considerable time if the server is waiting for a lock or processing a large sort. If this is unacceptable, always call dbdataready before dbresults and set the DB-Library time-out to regain control periodically.


This function sets up the next statement in the command batch for processing. It is called after dbsqlexec or dbsqlok. The dbresults function returns SUCCEED or NO_MORE_RESULTS on the first call if dbsqlexec or dbsqlok has returned SUCCEED, unless a network error or out-of-memory error has occurred. After dbresults returns SUCCEED, the user typically processes any rows with dbnextrow.

The dbresults function must be called for each statement in the command batch, whether or not the statement returns any rows. If the application code doesn't know how many statements are in the batch, dbresults can be called until it returns NO_MORE_RESULTS. Ordinarily, call dbresults one time for any stored procedure in the command batch. However, if the stored procedure contains more than one Transact-SQL SELECT statement, call dbresults one time for each SELECT statement. The easiest way to do this is to continue to call dbresults until it returns NO_MORE_RESULTS.

You must call dbresults until it returns NO_MORE_RESULTS, or any continued use of the DBPROCESS causes the DB-Library error 10038 "Results Pending".


This example shows the typical sequence of calls when using dbresults with dbsqlexec:

DBINT   xvariable;
DBCHAR   yvariable[10];

// Read the query into the command buffer. 
dbcmd(dbproc, "SELECT x = 100, y = 'hello'");

// Send the query to SQL Server. 
// Get ready to process the results of the query. 
// Bind column data to program variables. 
dbbind(dbproc, 1, INTBIND, (DBINT) 0, (BYTE *) &xvariable);
dbbind(dbproc, 2, STRINGBIND, (DBINT) 0, yvariable);
// Now process each row. 
while (dbnextrow(dbproc) != NO_MORE_ROWS)
   // C-code to print or process row data 

See Also