Home All Groups Group Topic Archive Search About

Fetching the wrong value in structure varible....

Author
23 Jun 2006 7:15 AM
Shahul
Dear Pals,

In my win32 console application, using the ODBC ver.3, trying to fetch the
records from the Table. While fetching the resultset, some variables are not
retrieving the correct value. Here the scenario.

Table1 has following two fields,
Table1:
*****
smallint    f1
smallint    f2

Having the structure as follows:
struct Tempstruct
{
    short a;
    char a1;
    short b;
}structvalue;

Code:
*****
////////////////////////////////////////////////////////////////////////////////////////
SQLHSTMT rsTemp;

sprintf(Sql,"SELECT f1, f2 FROM Table1");

//After Execution

nReturn = SQLBindCol(rsTemp, 1, SQL_C_SHORT,(SQLPOINTER)&structvalue.a,
sizeof(structvalue.a), &dtMaxLen);
nReturn = SQLBindCol(rsTemp, 1, SQL_C_SHORT,(SQLPOINTER)&structvalue.b,
sizeof(structvalue.b), &dtMaxLen);

for(nRows = 0; (nReturn = SQLFetch(rsTemp))==SQL_SUCCESS ||
nReturn==SQL_SUCCESS_WITH_INFO;)
{
    //Value in variable structvalue.b is not correctly retrieved here.
}

nReturn = SQLCloseCursor(rsTemp);
nReturn = SQLFreeStmt(rsTemp, SQL_UNBIND);
//////////////////////////////////////////////////////////////////////////////////////////////////

In the above code, I am binding the fields
    1. f1 in structvalue.a and
     2. f2 in structvalue.b

Note : The structure has three fields and I have not used the second field
a11 in SQLBindcol.

While fetching, value in f1 is bound correctly in structvalue.a, but f2
value is not bound correctly in structvalue.b.

Can any one give me the solution to solve this problem or any idea?

Awaiting for your valuable reply.

@ Shahul.

AddThis Social Bookmark Button