ADO Stream / SQL Server FOR XML


2005-05-12 03:17:02 AM
delphi175
The following doesn't work. It fails on the Command.Execute line, with the
error:
Parameter object is improperly defined. Inconsistent or incomplete
information was provided.
function SQLtoXML(Conn: TADOConnection; szSQL: string): string;
const
adExecuteStream = 1024;
var
szXML: WideString;
Command: _Command;
Stream: OleVariant;
RecordsAffected: OleVariant;
Parameters: OleVariant;
begin
szSQL := 'SELECT * FROM Products FOR XML AUTO, ELEMENTS';
Command := CreateOleObject('ADODB.Command') as _Command;
Command.Set_ActiveConnection(Conn.ConnectionObject);
Command.CommandType := ADOInt.adCmdText;
Command.CommandText := szSQL;
Stream := CreateOleObject('ADODB.Stream');
Stream.Open;
Command.Properties['Output Stream'].Value := Stream;
Command.Execute(RecordsAffected, Parameters, adExecuteStream);
Stream.Position := 0;
Result := '<?xml
version=''1.0''?>'+'<Results>'+Stream.ReadText+'</Results>';
end;
i've been following the examples in
tinyurl.com/cfcdk
tinyurl.com/8g2ew
tinyurl.com/9jzyp
tinyurl.com/78vga
and well, pretty much everything from
tinyurl.com/7nhur
but you know, Delphi isn't the greatest as a Windows development tool.