Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

c code,ado

0 views
Skip to first unread message

igg via SQLMonster.com

unread,
May 1, 2010, 8:10:32 AM5/1/10
to
c++ ado
strcpy(sqlbuf, "select a, b, c, (case when (y=2) then d else null end) as
d
pRS->Open(sqlbuf,vtMissing, AdoNS::adOpenKeyset, AdoNS::adLockBatchOptimistic,
-1);
while(pRS->adoEOF == false)
{
//how do i read the values a, b, c and d?.
//When i try to read the value d , i get the mismatch error.
}

--
Message posted via http://www.sqlmonster.com

Erland Sommarskog

unread,
May 1, 2010, 9:46:56 AM5/1/10
to
igg via SQLMonster.com (u53571@uwe) writes:
> c++ ado
> strcpy(sqlbuf, "select a, b, c, (case when (y=2) then d else null
> end) as d
> pRS->Open(sqlbuf,vtMissing, AdoNS::adOpenKeyset,
> AdoNS::adLockBatchOptimistic,> -1);
> while(pRS->adoEOF == false)
> {
> //how do i read the values a, b, c and d?.
> //When i try to read the value d , i get the mismatch error.
> }

What code do you try? And exactly what error message do you get?

Is there any requirement that you use ADO? I would suggest that the
best alternative to connect to SQL Server from C++ is ODBC, since there
is an ODBC driver which supports all features in SQL 2008, but with
ADO you are locked to what SQL 2000 provides.

--
Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

igg via SQLMonster.com

unread,
May 1, 2010, 12:45:50 PM5/1/10
to
i had no problem with reading the values for a, b and c. But had problem with
reading the d value. Something like:
with this i was getting mismatch error.
strcpy(strbuf,pRS->Fields->GetItem("d")->Value);
with this i was getting an unusual negative value.
sprintf(strbuf, "%d", pRS->Fields->GetItem("d")->Value);

--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-connectivity/201005/1

Erland Sommarskog

unread,
May 1, 2010, 5:40:00 PM5/1/10
to
igg via SQLMonster.com (u53571@uwe) writes:
> i had no problem with reading the values for a, b and c. But had problem
> with reading the d value. Something like:
> with this i was getting mismatch error.
> strcpy(strbuf,pRS->Fields->GetItem("d")->Value);
> with this i was getting an unusual negative value.
> sprintf(strbuf, "%d", pRS->Fields->GetItem("d")->Value);

And what data type is d? How do you check for NULL values?

igg via SQLMonster.com

unread,
May 2, 2010, 2:16:34 AM5/2/10
to
d is int or small int. that is what i am trying to figure out, how to check
for null values.

Erland Sommarskog wrote:
>> i had no problem with reading the values for a, b and c. But had problem
>> with reading the d value. Something like:
>> with this i was getting mismatch error.
>> strcpy(strbuf,pRS->Fields->GetItem("d")->Value);
>> with this i was getting an unusual negative value.
>> sprintf(strbuf, "%d", pRS->Fields->GetItem("d")->Value);
>
>And what data type is d? How do you check for NULL values?
>
>

--

Erland Sommarskog

unread,
May 2, 2010, 6:48:07 AM5/2/10
to
igg via SQLMonster.com (u53571@uwe) writes:
> d is int or small int. that is what i am trying to figure out, how to
> check for null values.

It would certainly have helped if you had asked that from the beginning!

The Value property is a Variant. You find the definition of this data type
on http://msdn.microsoft.com/en-us/library/ms221627%28VS.90%29.aspx.

0 new messages