Skip to content

Commit bec3491

Browse files
authored
Update using-sqlgetdiagrec-and-sqlgetdiagfield.md
1 parent 2fd6c43 commit bec3491

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

docs/odbc/reference/develop-app/using-sqlgetdiagrec-and-sqlgetdiagfield.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ GetSQLStmt(SQLStmt);
4646
4747
// Execute the SQL statement and return any errors or warnings.
4848
rc1 = SQLExecDirect(hstmt, SQLStmt, SQL_NTS);
49-
if ((rc1 == SQL_SUCCESS_WITH_INFO) || (rc1 == SQL_ERROR)) {
50-
// Get the status records.
49+
if ((rc1 == SQL_SUCCESS_WITH_INFO) || (rc1 == SQL_ERROR)) {
50+
SQLLEN numRecs = 0;
51+
  SQLGetDiagField(SQL_HANDLE_STMT, hstmt, 0, SQL_DIAG_NUMBER, &numRecs, 0, 0);
52+
  // Get the status records.
5153
i = 1;
52-
while ((rc2 = SQLGetDiagRec(SQL_HANDLE_STMT, hstmt, i, SqlState, &NativeError,
54+
while (i <= numRecs && (rc2 = SQLGetDiagRec(SQL_HANDLE_STMT, hstmt, i, SqlState, &NativeError,
5355
Msg, sizeof(Msg), &MsgLen)) != SQL_NO_DATA) {
5456
DisplayError(SqlState,NativeError,Msg,MsgLen);
5557
i++;

0 commit comments

Comments
 (0)