--- title: "SQLGetData | Microsoft Docs" ms.custom: "" ms.date: "03/17/2017" ms.prod: "sql-server-2016" ms.reviewer: "" ms.suite: "" ms.technology: - "docset-sql-devref" ms.tgt_pltfrm: "" ms.topic: "reference" apitype: "DLLExport" helpviewer_keywords: - "SQLGetData function" ms.assetid: 204848be-8787-45b4-816f-a60ac9d56fcf caps.latest.revision: 42 author: "JennieHubbard" ms.author: "jhubbard" manager: "jhubbard" --- # SQLGetData [!INCLUDE[SNAC_Deprecated](../../includes/snac-deprecated.md)] **SQLGetData** is used to retrieve result set data without binding column values. **SQLGetData** can be called successively on the same column to retrieve large amounts of data from a column with a **text**, **ntext**, or **image** data type. There is no requirement that an application bind variables to fetch result set data. The data of any column can be retrieved from the [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] Native Client ODBC driver by using **SQLGetData**. The [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] Native Client ODBC driver does not support using **SQLGetData** to retrieve data in random column order. All unbound columns processed with **SQLGetData** must have higher column ordinals than the bound columns in the result set. The application must process data from the lowest unbound ordinal column value to the highest. Attempting to retrieve data from a lower ordinally numbered column results in an error. If the application is using server cursors to report result set rows, the application can refetch the current row and then fetch the value of a column. If a statement is executed on the default read-only, forward-only cursor, you must re-execute the statement to back up **SQLGetData**. The [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] Native Client ODBC driver accurately reports the length of **text**, **ntext**, and **image** data retrieved using **SQLGetData**. The application can make good use of the *StrLen_or_IndPtr* parameter return to retrieve long data rapidly. > [!NOTE] > For large value types, *StrLen_or_IndPtr* will return SQL_NO_TOTAL in cases of data truncation. ## SQLGetData Support for Enhanced Date and Time Features Result column values of date/time types are converted as described in [Conversions from SQL to C](../../relational-databases/native-client-odbc-date-time/datetime-data-type-conversions-from-sql-to-c.md). For more information, see [Date and Time Improvements (ODBC)](../../relational-databases/native-client-odbc-date-time/date-and-time-improvements-odbc.md). ## SQLGetData Support for Large CLR UDTs **SQLGetData** supports large CLR user-defined types (UDTs). For more information, see [Large CLR User-Defined Types (ODBC)](../../relational-databases/native-client/odbc/large-clr-user-defined-types-odbc.md). ## Example ``` SQLHDBC hDbc = NULL; SQLHSTMT hStmt = NULL; long lEmpID; PBYTE pPicture; SQLINTEGER pIndicators[2]; // Get an environment, connection, and so on. ... // Get a statement handle and execute a command. SQLAllocHandle(SQL_HANDLE_STMT, hDbc, &hStmt); if (SQLExecDirect(hStmt, (SQLCHAR*) "SELECT EmployeeID, Photo FROM Employees", SQL_NTS) == SQL_ERROR) { // Handle error and return. } // Retrieve data from row set. SQLBindCol(hStmt, 1, SQL_C_LONG, (SQLPOINTER) &lEmpID, sizeof(long), &pIndicators[0]); while (SQLFetch(hStmt) == SQL_SUCCESS) { cout << "EmployeeID: " << lEmpID << "\n"; // Call SQLGetData to determine the amount of data that's waiting. if (SQLGetData(hStmt, 2, SQL_C_BINARY, pPicture, 0, &pIndicators[1]) == SQL_SUCCESS_WITH_INFO) { cout << "Photo size: " pIndicators[1] << "\n\n"; // Get all the data at once. pPicture = new BYTE[pIndicators[1]]; if (SQLGetData(hStmt, 2, SQL_C_DEFAULT, pPicture, pIndicators[1], &pIndicators[1]) != SQL_SUCCESS) { // Handle error and continue. } delete [] pPicture; } else { // Handle error on attempt to get data length. } } ``` ## See Also [SQLGetData Function](http://go.microsoft.com/fwlink/?LinkId=59350) [ODBC API Implementation Details](../../relational-databases/native-client-odbc-api/odbc-api-implementation-details.md)