System.Data.SqlClient.SqlDataReader.SqlDataReader.GetSqlXml C# (CSharp) Method

GetSqlXml() public method

public GetSqlXml ( int i ) : SqlXml
i int
return System.Data.SqlTypes.SqlXml
		public virtual SqlXml GetSqlXml (int i)
		{
			object value = GetSqlValue (i);
			if (!(value is SqlXml)) {
				if (value is DBNull) {
					throw new SqlNullValueException ();
				} else if (command.Tds.TdsVersion <= TdsVersion.tds80 && value is SqlString) {
					// Workaround for TDS 7/8/8.1 clients
					// Xml column types are supported only from Sql Server 2005 / TDS 9, however
					// when a TDS 7/8/8.1 client requests for Xml column data, Sql Server 2005 returns
					// it as NTEXT
					MemoryStream stream = null;
					if (!((SqlString) value).IsNull)
						stream = new MemoryStream (Encoding.Unicode.GetBytes (value.ToString()));
					value = new SqlXml (stream);
				} else {
					throw new InvalidCastException ("Type is " + value.GetType ().ToString ());
				}
			}
			return (SqlXml) value;
		}
#endif // NET_2_0