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"); }
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; StreamWriter writer = File.CreateText(Application.StartupPath + @"\sqlxmlresults.xml"); cmd.ExecuteToStream(writer.BaseStream); writer.Close(); webBrowser1.Navigate(Application.StartupPath + @"\sqlxmlresults.xml"); }
private void Form1_Load(object sender, EventArgs e) { string strConn = @"Provider=SQLOLEDB;server=.;database=northwind;integrated security=SSPI"; SqlXmlCommand cmd = new SqlXmlCommand(strConn); cmd.CommandText = "select EmployeeID,FirstName,LastName from employees for xml auto"; cmd.RootTag = "root"; cmd.XslPath = $"{Application.StartupPath}\\employees.xslt"; StreamWriter writer = File.CreateText($"{Application.StartupPath}\\sqlxmlresults.htm"); cmd.ExecuteToStream(writer.BaseStream); writer.Close(); webBrowser1.Navigate($"{Application.StartupPath}\\sqlxmlresults.htm"); }
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"); }
private void button1_Click(object sender, EventArgs e) { if (textBox1.Text == "") { MessageBox.Show("Please enter SELECT query"); return; } try { string strConn = @"Provider=SQLOLEDB;server=.\sqlexpress;database=northwind;integrated security=SSPI"; SqlXmlCommand cmd = new SqlXmlCommand(strConn); cmd.CommandText = textBox1.Text; StreamWriter writer = File.CreateText($"{Application.StartupPath}\\sqlxmlresults.xml"); cmd.ExecuteToStream(writer.BaseStream); writer.Close(); webBrowser1.Navigate($"{Application.StartupPath}\\sqlxmlresults.xml"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }