Per recuperare i risultati in uno stream, la query deve includere "FOR XML AUTO". cambiarne anche l'adExecuteStream testo per il valore della costante 1024.
codice completo:
Dim myStream, myConnection, myCommand
Set myStream = CreateObject("ADODB.Stream")
Set myConnection = CreateObject("ADODB.Connection")
Set myCommand = CreateObject("ADODB.Command")
myConnection.Open "Provider=SQLOLEDB;Integrated Security=SSPI;" & _
"Persist Security Info=False;Initial Catalog=DSIPAR;Data Source=.\DSIDATA"
myCommand.ActiveConnection=myConnection
myCommand.CommandText="SELECT itemsgt,item FROM NIFItem FOR XML AUTO"
myStream.Open
myCommand.Properties("Output Stream") = myStream
myCommand.Properties("xml root") = "root"
myCommand.Execute ,,1024 'instead of adExecuteStream
myStream.Position=0
myStream.Charset="ISO-8859-1"
Dim strxml
strxml = myStream.ReadText
MsgBox (strxml)
Se non avete bisogno di un ruscello e invece volete leggere i valori di itemsgt e la voce, provate questo invece:
Dim myStream, myConnection, myCommand, adoRec
Set myStream = CreateObject("ADODB.Stream")
Set myConnection = CreateObject("ADODB.Connection")
Set myCommand = CreateObject("ADODB.Command")
myConnection.Open "Provider=SQLOLEDB;Integrated Security=SSPI;" & _
"Persist Security Info=False;Initial Catalog=DSIPAR;Data Source=.\DSIDATA"
myCommand.ActiveConnection=myConnection
myCommand.CommandText="SELECT itemsgt,item FROM NIFItem"
SET adoRec = myCommand.Execute()
'Get the first results
If Not adoRec.EOF then
MsgBox "itemsgt = " & adoRec(0) & vbcrlf & "item=" & adoRec(1)
End If
'Iterate through the results
While Not adoRec.EOF
itemsgt = adoRec(0)
item = adoRec(1)
'MsgBox "itemsgt = " & itemsgt & vbcrlf & "item=" & item
adoRec.MoveNext
Wend
fonte
2009-05-15 15:49:12
Come sottolineato da Jose, l'istruzione SQL non recupera le informazioni sotto forma di XML. Ad esempio, non utilizza FOR XML – shahkalpesh