all groups > sql server odbc > july 2006 >
You're in the

sql server odbc

group:

Issue in binding a varchar field to a structure element


Issue in binding a varchar field to a structure element Uma - Chellasoft
7/5/2006 12:00:00 AM
sql server odbc:
Hai,

I am working with VC++ console application. For SQLServer DB accessing, I am
using ODBC connectivity.

I am facing problem while binding the columns of the result set to
individual elements of the structure.

For example,

struct Sample
{
char e1;
short e2;
}s1;

For the above structure elements, if I bind the result set of the below
query with f1(varchar(1)) and f2(smallint)

SELECT f1, f2 from t1

I am not getting the value of f2 in s1.e2 while binding both the columns. If
I am not binding f1 to s1.e1, then I am getting f2 value correctly in s1.e2.
Will varchar(1) take an additional character for null character, can anyone
give me a permanent solution for this? It solves me the problem if I declare
e1 as char e1[2], but I don't want to give extra byte for all char fields,
so please help me with an exact reason for this happening. My structure is
alligned with pragma pack (1). How will the columns in the result set be
alligned?

Thanks in advance,
Uma


Re: Issue in binding a varchar field to a structure element Arnie
7/6/2006 8:57:16 AM
[quoted text, click to view]

A VARCHAR(n) requires a char buffer of size n+1 in order to hold
the trailing zero. Have you tried binding as a CHAR(1) with a
length of 1 in the binding staement?

- Arnie

Re: Issue in binding a varchar field to a structure element Uma - Chellasoft
7/10/2006 12:00:00 AM
[quoted text, click to view]


I am getting the same problem with CHAR(1) also. Is there any other solution
other than size n+1.

Thanks in advance,
Uma

[quoted text, click to view]

AddThis Social Bookmark Button