Sends the CommandText to the Connection and builds an XMLReader. If the first column in the result set is not of a supported type (any character, binary type, or DB2Type.XML), an Invalid Column Type exception will be thrown.
[Visual Basic]
Public Function ExecuteXmlReader() As XmlReader
[C#]
public XmlReader ExecuteXmlReader();
[C++]
public: XmlReader* ExecuteXmlReader();
[JScript]
public function ExecuteXmlReader() : XmlReader;
An XmlReader object.
When RetrieveXmlInBinaryFormat is set to true, this method will throw an InvalidOperation exception.
Exception type | Condition |
---|---|
InvalidColumnTypeException | The first column in the result set is not of a supported type (any character or binary type). |
InvalidOperationException | At least one selected column is a XML data type and RetrieveXmlInBinaryFormat is true. |
[C#] The following example demonstrates how to read XML data using an XmlReader.
[C#]
public static string getProdData(DB2Connection conn)
{
String xmlString = "";
String cmdSQL = "SELECT description FROM product WHERE pid='100-101-01'";
DB2Command cmd = new DB2Command(cmdSQL, conn);
XmlReader reader = cmd.ExecuteXmlReader();
while (reader.Read())
{
xmlString = reader.ReadOuterXml();
}
return xmlString;
}