Wrox Home  
Search P2P Archive for: Go

  Return to Index  

activex_data_objects thread: Ado and Sql_Variant Data Type


Message #1 by rob@g... on Thu, 21 Mar 2002 18:46:16
I am writing a simple program to dump the results of a query to Excel.  I 
am using the most recent version of Ado (2.7) with SQL2k.  When I try to 
pull in the recordset from a table with all fields defined as SQL_Variant, 
I get nothing but garbage for results.  I have not seen this error 
anywhere on the net, nor microsoft's web page.  So I am not sure what to 
do.  Here is an example of my dilemma.

create table rtemp (f1 sql_variant,f2 sql_variant)
insert into rtemp (f1,f2) values ('6','rob')
insert into rtemp (f1,f2) values (6,getdate())

select * from rtemp
   6	rob                      <------ results correct in Query Analyzer
   6	2002-03-21 10:29:04.840

(in VB)
Rs.Open "Select * from rtemp", MyConnection, adOpenStatic, adLockReadOnly
print Rs.fields(0).value ----> " "
print Rs.fields(1).value ----> "?"
Rs.MoveNext
print Rs.fields(0).value ----> ""
print Rs.fields(1).value ----> "? ?¬"

In vb, using ado, I get garbage returned.  Please let me know if I am 
doing something wrong or if this is a problem with Ado.  The only 
workaround I see is casting each value to varchar in SQL and then 
importing them into VB, only to reconvert them back to variant.  A major 
pain in the butt (especially when I have 119 rows, and 17 queries to 
change).

Thanks much!
Rob

  Return to Index