Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("-----------STARTING APPLICATION-----------");
            Console.WriteLine("EXECUTING XML VIEW FILE");

            SqlXmlCommand cmd = new SqlXmlCommand("Provider=sqloledb; Data Source=(local);Initial Catalog=TK431Chapter8;UID=sa");

            Console.WriteLine("Loading Updategram");
            cmd.CommandStream = new FileStream("NewLogRecordUpdategram.xml", FileMode.Open, FileAccess.Read);
            cmd.CommandType = SqlXmlCommandType.DiffGram;

            Console.WriteLine("Creating parameters");
            SqlXmlParameter ID = cmd.CreateParameter();
            ID.Name = "@ID";
            ID.Value = "6";

            SqlXmlParameter appName = cmd.CreateParameter();
            appName.Name = "@AppName";
            appName.Value = "CustomerAssistance";

            SqlXmlParameter message = cmd.CreateParameter();
            message.Name = "@Message";
            message.Value = @"<logRecord machine='WebHostingServer' timestamp='2000-01-01T06:00:00Z'>
                     <post eventType='appStart'>
                        <moreInformation>The web server is under attack</moreInformation>
                    </post>
                </logRecord>";

            Console.WriteLine("Executing!");
            cmd.ExecuteNonQuery();

            Console.WriteLine("-----------APPLICATION FINISHED-----------");
            Console.ReadLine();
        }
Пример #2
0
        private void PersistChanges(string serializedEmployees, bool delete)
        {
            SqlXmlCommand command = new SqlXmlCommand(_SqlXmlconnectionString);

            command.CommandType = SqlXmlCommandType.Sql;
            command.CommandText = "exec PersistEmployees ?, ?";
            SqlXmlParameter param = command.CreateParameter();

            param.Value = serializedEmployees;
            SqlXmlParameter param2 = command.CreateParameter();

            param2.Value = delete ? 1 : 0;
            command.ExecuteNonQuery();
        }
Пример #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("Please enter Employee ID");
                return;
            }

            int result;

            if (!int.TryParse(textBox1.Text, out result))
            {
                MessageBox.Show("Employee ID must be an integer");
                return;
            }

            string        strConn = @"Provider=SQLOLEDB;server=.;database=northwind;integrated security=SSPI";
            string        sql     = "select employeeid,firstname,lastname from employees where employeeid=? for xml auto,root('MyRoot')";
            SqlXmlCommand cmd     = new SqlXmlCommand(strConn);

            cmd.CommandText = sql;
            SqlXmlParameter param = cmd.CreateParameter();

            param.Value = textBox1.Text;
            StreamWriter writer = File.CreateText($"{Application.StartupPath}\\sqlxmlresults.xml");

            cmd.ExecuteToStream(writer.BaseStream);
            writer.Close();
            webBrowser1.Navigate($"{Application.StartupPath}\\sqlxmlresults.xml");
        }
Пример #4
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);
            }
        }
Пример #5
0
        public void CleanDatabase()
        {
            SqlXmlCommand command = new SqlXmlCommand(_SqlXmlconnectionString);

            command.CommandType = SqlXmlCommandType.Sql;
            command.CommandText = "delete address;delete Employee";
            SqlXmlParameter param = command.CreateParameter();

            command.ExecuteNonQuery();
        }
Пример #6
0
        public Employee[] GetEmployee(string lastName)
        {
            SqlXmlCommand command = new SqlXmlCommand(_SqlXmlconnectionString);

            command.CommandType = SqlXmlCommandType.Sql;
            command.CommandText = "exec FetchEmployee ?";
            SqlXmlParameter param = command.CreateParameter();

            param.Value = lastName;
            return(DeserializeEmployee(command.ExecuteXmlReader()));
        }
Пример #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            string        strConn = @"Provider=SQLOLEDB;server=.\sqlexpress;database=northwind;integrated security=SSPI";
            string        sql     = "select employeeid,firstname,lastname from employees where employeeid=? for xml auto,root('MyRoot')";
            SqlXmlCommand cmd     = new SqlXmlCommand(strConn);

            cmd.CommandText = sql;
            SqlXmlParameter param = cmd.CreateParameter();

            param.Value = textBox1.Text;
            StreamWriter writer = File.CreateText(Application.StartupPath + @"\sqlxmlresults.xml");

            cmd.ExecuteToStream(writer.BaseStream);
            writer.Close();
            webBrowser1.Navigate(Application.StartupPath + @"\sqlxmlresults.xml");
        }
Пример #8
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);
            }
        }