using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Xml;
using System.Data.SqlTypes;

namespace XmlClient
{
    class Program
    {
        static void Main(string[] args)
        {
            SqlConnection conn = new SqlConnection("server=.;integrated security=sspi;database=pubs");
            SqlCommand cmd = new SqlCommand("select * from xmltab where xmlorder.exist('/Order/LineItems/LineItem[Description=''Cola'']') = 1" , conn);
            conn.Open();
            SqlDataReader rdr = cmd.ExecuteReader();
            while (rdr.Read())
            {
                SqlXml x = rdr.GetSqlXml(0);
                XmlReader xr = x.CreateReader();
                xr.Read();
                Console.WriteLine(xr.ReadOuterXml());
                xr.Close();
            }
              
            rdr.Close();
            cmd.Dispose();
            conn.Dispose();
        }
    }
}
