示例#1
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");
        }
示例#2
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();
        }
示例#3
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()));
        }
示例#4
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();
        }
示例#5
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");
        }