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"); }
public void CleanDatabase() { SqlXmlCommand command = new SqlXmlCommand(_SqlXmlconnectionString); command.CommandType = SqlXmlCommandType.Sql; command.CommandText = "delete address;delete Employee"; SqlXmlParameter param = command.CreateParameter(); command.ExecuteNonQuery(); }
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())); }
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(); }
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"); }