SqlDataReader.GetXmlReader(Int32) 方法

定義

擷取 XML 型別的資料做為XmlReaderRetrieves data of type XML as an XmlReader.

public:
 virtual System::Xml::XmlReader ^ GetXmlReader(int i);
public virtual System.Xml.XmlReader GetXmlReader (int i);
abstract member GetXmlReader : int -> System.Xml.XmlReader
override this.GetXmlReader : int -> System.Xml.XmlReader
Public Overridable Function GetXmlReader (i As Integer) As XmlReader

參數

i
Int32

指定的資料行值。The value of the specified column.

傳回

已傳回的物件。The returned object.

例外狀況

在資料擷取期間,連線中斷或關閉。The connection drops or is closed during the data retrieval.

SqlDataReader在資料擷取期間已關閉。The SqlDataReader is closed during the data retrieval.

沒有可供讀取的資料 (例如,第一個 Read() 沒有被呼叫,或傳回 false)。There is no data ready to be read (for example, the first Read() hasn't been called, or returned false).

嘗試在循序模式下讀取先前讀取的資料行。Trying to read a previously read column in sequential mode.

有進行中的非同步作業。There was an asynchronous operation in progress. 當在循序模式中執行時,此適用於所有 Get* 方法,因為在讀取資料流時可能會呼叫它們。This applies to all Get* methods when running in sequential mode, as they could be called while reading a stream.

嘗試讀取不存在的資料行。Trying to read a column that does not exist.

傳回的型別不是 xml。The returned type was not xml.

備註

GetXmlReader 傳回的 XmlReader 物件不支援非同步作業。The XmlReader object returned by GetXmlReader does not support asynchronous operations. 如果您需要在 XmlReader上進行非同步作業,請將 XML 資料行轉換成伺服器上的 NVARCHAR (MAX),並搭配使用 GetTextReaderCreateIf you require asynchronous operations on an XmlReader, cast the XML column to an NVARCHAR(MAX) on the server and use GetTextReader with Create.

XmlReader 引發的 SqlException 例外狀況會擲回 XmlException 例外狀況;檢查 SqlException的內部例外狀況。SqlException exceptions raised from XmlReader are thrown as XmlException exceptions; check the inner exception for the SqlException.

SequentialAccess 生效時,GetChars 將會引發 InvalidOperationException 的例外狀況,並在 GetXmlReader 傳回的物件上使用。GetChars will raise an InvalidOperationException exception when used on an object returned by GetXmlReader when SequentialAccess is in effect.

如需詳細資訊,請參閱SqlClient 串流支援For more information, see SqlClient Streaming Support.

適用於