?
Solved

What is the best way to get a varchar(max) from ADO

Posted on 2008-10-16
7
Medium Priority
?
648 Views
Last Modified: 2012-05-05
I have a SQL Express column of type varchar(max).  What is the best way to extract the column value using ADO in VBA?  Do I  need to declare and use the Windows API Function: WideCharToMultiByte to use the value as text?

A value of correct length is returned but not as a recognizable or usable string.
Set oADOConn = CreateObject("ADODB.Connection") 
oADOConn.ConnectionString = oConnString
oADOConn.Open
 
Set oADOCommand = CreateObject("ADODB.Command")
oADOCommand.ActiveConnection = oADOConn
oADOCommand.CommandType = adCmdStoredProc
oADOCommand.NamedParameters = False
oADOCommand.CommandText = "GetSCFText"    
Set oADORecSet = oADOCommand.Execute
   
vSCFText = oADORecSet.fields("SCFText").value
        
    oADOConn.Close                                                        ' Close the ADO Connection
    
    Set oADOConn = Nothing                                                ' Release the ADO Connection
    Set oADOCommand = Nothing                                             ' Release the ADO Command

Open in new window

0
Comment
Question by:MDKIMZEY
  • 4
  • 3
7 Comments
 
LVL 9

Expert Comment

by:JonMny
ID: 22732091
String variable type will work fine
dim  vSCFText as string
 
0
 

Author Comment

by:MDKIMZEY
ID: 22733459
Actually the string comes through as binary.
0
 
LVL 9

Expert Comment

by:JonMny
ID: 22733479
I tested it on my system and works fine, what is stored in your field? How large is it?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:MDKIMZEY
ID: 22733651
JonMny, Thanks much for looking at this and trying it on your system - the column SCFText is declared as SCFTEXT varchar(max)  in SQL Express 2005.

What version of SQL and MDAC are you using?
0
 
LVL 9

Accepted Solution

by:
JonMny earned 375 total points
ID: 22733761
I have sql server 2008 not sure what version of mdac, I used excel 2007 to test it.
Sub sdefla()
Set oADOConn = CreateObject("ADODB.Connection")
oADOConn.ConnectionString = "server=.\dev;Integrated Security=SSPI;database=test;provider=sqloledb"
 
 
 
oADOConn.Open
 
Set oADOCommand = CreateObject("ADODB.Command")
oADOCommand.ActiveConnection = oADOConn
oADOCommand.CommandType = 4
oADOCommand.NamedParameters = False
oADOCommand.CommandText = "gettest"
Set oADORecSet = oADOCommand.Execute
   
vSCFText = oADORecSet.fields("test").Value
        
    oADOConn.Close                                                        ' Close the ADO Connection
    
    Set oADOConn = Nothing                                                ' Release the ADO Connection
    Set oADOCommand = Nothing                                             ' Release
End Sub

Open in new window

0
 

Author Closing Comment

by:MDKIMZEY
ID: 31506745
I appreciate your looking at this - I changed the column definition from varchar(max) to text - this did the trick...
0
 

Author Comment

by:MDKIMZEY
ID: 22734059
This may be an issue with SQL Express 2005 and ADO 2.8 - the solution I used was to change the varchar(max) column to a text column and add a SET TEXTSIZE statement to the stored procedure.  

I did try using a call to:

Private Declare Function WideCharToMultiByte Lib "kernel32" _
    (ByVal codepage As Long, ByVal dwFlags As Long, _
    lpWideCharStr As Any, ByVal cchWideChar As Long, _
    lpMultiByteStr As Any, ByVal cchMultiByte As Long, _
    ByVal lpDefaultChar As String, _
    ByVal lpUsedDefaultChar As Long) As Long

on the binary data in the Value property of the ADO Field.  This had no affect.


0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question