Tuesday, 13 August 2013

XML Created in TSQL Used as ADODB.Recordset

XML Created in TSQL Used as ADODB.Recordset

I am attempting to use XML that was generated from a stored procesure in
our MS SQL database as a Recordset in a VS2005 Application. The issue I am
having is that when reading in the xml as a string, the string result
comes in as "System.Byte[]". Seeing this I changed the datatype from
String to Byte() and tried to use the Byte array. The Byte array does not
seem to have anything to do with the data I want to be receiving. I am
wondering if there is a way to handle SQL generated XML files that I am
not aware of. Here is some sample code.
This is what the result of the stored procedure looks like when in SQL SMS

With this code I get the System.byte[] as my string:
Dim ADOrs As ADODB.Recordset
Dim SQLString1 As New System.Text.StringBuilder(180)
Dim catzzz as String
SQLString1.Append("exec reports_selectReportMetaData @companyCode = '001'")
ADOrs = fnReturnRecordset(SQLString1.ToString) 'function executes the query
Do While Not ADOrs.EOF
catzzz = ADOrs("XML_F52E2B61-18A1-11d1-B105-00805F49916B").Value.ToString
Debug.WriteLine(catzzz)
Loop
This is the way I get the really odd Byte Array
Dim ADOrs As ADODB.Recordset
Dim SQLString1 As New System.Text.StringBuilder(180)
Dim catzzz As Byte()
SQLString1.Append("exec reports_selectReportMetaData @companyCode = '001'")
ADOrs = fnReturnRecordset(SQLString1.ToString)'function executes the query
Do While Not ADOrs.EOF
catzzz = ADOrs("XML_F52E2B61-18A1-11d1-B105-00805F49916B").Value
Loop
The Byte array looks like
And when converted to ASCII using
catX = System.Text.Encoding.Default.GetString(catzzz)
the first three characters (that should be <rt ) Come up as

So I think my main issue is that I am missing the proper way to bring in
the XML created in SQL
Any Ideas would be appricated!

No comments:

Post a Comment