Skip to main content

Posts

Showing posts from January, 2009

How to fetch NULL data into C-ODBC program?

From last two months I’m working on C-ODBC project, despite my expertise in Java. This was I encountered while development. Problem : C-ODBC API does not provide any function which fetch NULL data without throwing a runtime error. Solution : Need to provide an indicator , which get set when row data contained NULL for that specific column. 1. Define the long typed variable for holding indication about NULL data: SQLINTEGER i_first_name, i_last_name, i_age; // i for indicator 2. Passed this indicator variable to SQLBindCol function: SQLBindCol(hstmt, 1, SQL_C_CHAR, first_name, 100, &i_first_name); SQLBindCol(hstmt, 2, SQL_C_CHAR, last_name, 100, &i_larst_name); SQLBindCol(hstmt, 3, SQL_C_CHAR, age, 100, &i_age); More Information: http://msdn.microsoft.com/en-us/library/ms711010.aspx 3. Check whether we fetched any NULL data into a column by checking, if(i_first_name == SQL_NULL_DATA) { // I put a “null” string into fist_name variable. strcpy(fi