EDN Admin
Well-known member
Hi All,
I have a Windows Application that is very simple. Im testing a process for a latter larger scale project as a proof of concept.
So I have a simple button on a form that has code behind:
<pre class="prettyprint using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace xmlTest1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnWriter_Click(object sender, System.EventArgs e)
{
string myConnectionString = "Data Source=ukfil239win;Initial Catalog=FILPublishingSolutions;Integrated Security=True";
string mySelectQuery = "Select * From schedule";
System.IO.FileStream myFileStream = new System.IO.FileStream
("j:\mySchema.xml", System.IO.FileMode.Create);
System.Xml.XmlTextWriter MyXmlTextWriter = new System.Xml.XmlTextWriter
(myFileStream, System.Text.Encoding.Unicode);
try {
SqlConnection con = new SqlConnection(myConnectionString);
SqlDataAdapter daCust = new SqlDataAdapter(mySelectQuery, con);
DataSet ds = new DataSet();
daCust.Fill(ds, "ProdName");
//Write the XML along with the inline schema (default).
//ds.WriteXml(MyXmlTextWriter, XmlWriteMode.WriteSchema);
//Write the XML only.
ds.WriteXml(MyXmlTextWriter, XmlWriteMode.IgnoreSchema);
//Write the XML as a DiffGram.
//ds.WriteXml(MyXmlTextWriter, XmlWriteMode.DiffGram);
MessageBox.Show("Save complete");
}
catch (System.Exception ex) {
MessageBox.Show(ex.ToString());
}
finally {
MyXmlTextWriter.Close();
myFileStream.Close();
}
}[/code]
But when I start the application and click the button, nothing happens. No XML is generated at all. What could be wrong? I get no errors but no confirmations either.
Please advise.
Regards
Lee <hr class="sig Lee Warren
View the full article
I have a Windows Application that is very simple. Im testing a process for a latter larger scale project as a proof of concept.
So I have a simple button on a form that has code behind:
<pre class="prettyprint using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace xmlTest1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnWriter_Click(object sender, System.EventArgs e)
{
string myConnectionString = "Data Source=ukfil239win;Initial Catalog=FILPublishingSolutions;Integrated Security=True";
string mySelectQuery = "Select * From schedule";
System.IO.FileStream myFileStream = new System.IO.FileStream
("j:\mySchema.xml", System.IO.FileMode.Create);
System.Xml.XmlTextWriter MyXmlTextWriter = new System.Xml.XmlTextWriter
(myFileStream, System.Text.Encoding.Unicode);
try {
SqlConnection con = new SqlConnection(myConnectionString);
SqlDataAdapter daCust = new SqlDataAdapter(mySelectQuery, con);
DataSet ds = new DataSet();
daCust.Fill(ds, "ProdName");
//Write the XML along with the inline schema (default).
//ds.WriteXml(MyXmlTextWriter, XmlWriteMode.WriteSchema);
//Write the XML only.
ds.WriteXml(MyXmlTextWriter, XmlWriteMode.IgnoreSchema);
//Write the XML as a DiffGram.
//ds.WriteXml(MyXmlTextWriter, XmlWriteMode.DiffGram);
MessageBox.Show("Save complete");
}
catch (System.Exception ex) {
MessageBox.Show(ex.ToString());
}
finally {
MyXmlTextWriter.Close();
myFileStream.Close();
}
}[/code]
But when I start the application and click the button, nothing happens. No XML is generated at all. What could be wrong? I get no errors but no confirmations either.
Please advise.
Regards
Lee <hr class="sig Lee Warren
View the full article