Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("Please enter SELECT query");
                return;
            }

            try
            {
                string strConn = @"Provider=SQLOLEDB;server=.;database=northwind;integrated security=SSPI";

                SqlXmlCommand cmd = new SqlXmlCommand(strConn);
                cmd.CommandText = textBox1.Text;
                Stream       stream = cmd.ExecuteStream();
                StreamReader reader = new StreamReader(stream);
                StreamWriter writer = File.CreateText($"{Application.StartupPath}\\sqlxmlresults.xml");
                writer.Write(reader.ReadToEnd());
                writer.Close();
                webBrowser1.Navigate($"{Application.StartupPath}\\sqlxmlresults.xml");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            SqlXmlCommand   cmd = new SqlXmlCommand(connectionString);
            SqlXmlParameter parm;

            cmd.CommandText = "SELECT FirstName, LastName FROM Person.Contact WHERE LastName=? For XML Auto";
            parm            = cmd.CreateParameter();
            parm.Value      = "Achong";
            string strResult;

            try
            {
                Stream strm = cmd.ExecuteStream();
                strm.Position = 0;
                using (StreamReader sr = new StreamReader(strm))
                {
                    Console.WriteLine(sr.ReadToEnd());
                }
            }
            catch (SqlXmlException e)
            {
                //in case of an error, this prints error returned.
                e.ErrorStream.Position = 0;
                strResult = new StreamReader(e.ErrorStream).ReadToEnd();
                System.Console.WriteLine(strResult);
            }
        }
Пример #3
0
        static void ReadFromXMLView()
        {
            SqlXmlCommand cmd = new SqlXmlCommand("Provider=sqloledb;Data Source=DEMOS;Initial Catalog=TK431Chapter8;User Id=sa;");
            cmd.CommandText = "UniversalLogView.xml";
            cmd.CommandType = SqlXmlCommandType.TemplateFile;

            PrintXML(cmd.ExecuteStream(), true, "ReadFromXMLView.xml");
        }
Пример #4
0
        static void ReadFromAnnotatedSchema()
        {
            string XPATH = "UniversalLog/Log[@ID='3']";

            SqlXmlCommand cmd = new SqlXmlCommand("Provider=sqloledb;Data Source=DEMOS;Initial Catalog=TK431Chapter8;User Id=sa;");
            cmd.CommandText = XPATH;
            cmd.CommandType = SqlXmlCommandType.XPath;
            cmd.SchemaPath = "UniversalLogSchema.xsd";

            PrintXML(cmd.ExecuteStream(), true, "ReadFromAnnotatedSchema.xml");
        }
Пример #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            string        strConn = @"Provider=SQLOLEDB;server=.\sqlexpress;database=northwind;integrated security=SSPI";
            SqlXmlCommand cmd     = new SqlXmlCommand(strConn);

            cmd.CommandText = textBox1.Text;
            Stream       stream = cmd.ExecuteStream();
            StreamReader reader = new StreamReader(stream);
            StreamWriter writer = File.CreateText(Application.StartupPath + @"\sqlxmlresults.xml");

            writer.Write(reader.ReadToEnd());
            writer.Close();
            webBrowser1.Navigate(Application.StartupPath + @"\sqlxmlresults.xml");
        }
Пример #6
0
        private Stream GetXml(string filterTemplate)
        {
            SqlXmlCommand catalogCommand = new SqlXmlCommand(connString);

            catalogCommand.CommandType = SqlXmlCommandType.XPath;
            catalogCommand.CommandText = filterTemplate;
            catalogCommand.RootTag     = dataRootTag;
            catalogCommand.Namespaces  = dataNamespaces;
            catalogCommand.SchemaPath  = catalogSchemaFile;
            return(catalogCommand.ExecuteStream());

            /* For the time being
             * Stream xmlStream = File.OpenRead(@"D:\Reusable Components\DataAccessLogic\ProofOfConcept\ProofOfConcept\TestPUNCatalog.xml");
             * return xmlStream;
             */
        }
Пример #7
0
        static void Main(string[] args)
        {
            FileStream    xmlQuery = new FileStream("command.xml", FileMode.Open);
            SqlXmlCommand cmd      = new SqlXmlCommand(connectionString);

            cmd.CommandStream = xmlQuery;
            cmd.CommandType   = SqlXmlCommandType.Template;

            SqlXmlParameter parm;

            parm       = cmd.CreateParameter();
            parm.Name  = "@LastName";
            parm.Value = "Achong";

            cmd.ClientSideXml = true;
            cmd.RootTag       = "Person";

            string strResult;

            try
            {
                Stream strm = cmd.ExecuteStream();
                strm.Position = 0;
                using (StreamReader sr = new StreamReader(strm))
                {
                    Console.WriteLine(sr.ReadToEnd());
                }
            }
            catch (SqlXmlException e)
            {
                //in case of an error, this prints error returned.
                e.ErrorStream.Position = 0;
                strResult = new StreamReader(e.ErrorStream).ReadToEnd();
                System.Console.WriteLine(strResult);
            }
        }