DataSet : Error when trying to use ReadXml the 2nd time

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

On my application, i'm using this :

dataSet1.ReadXml(textBox1.Text, XmlReadMode.Auto);

This works fine the first time but the second time, if i changed the value
of textBox1.Text, dataSet1 is not reading the XML file which is in
textBox1.Text, but it's reading the XML file i've used the first time....

Do you know how to solve this ?

Thank You.
 
Thomas,

Are you sure of that it is not reading however just throw an error because
you did not clear it in advance?

Just a thought?

Cor
 
Hi,

Thank for your response.
But i'm clearing the dataSet before reading the XML file so i don't know why
i get this....


Another ideas ?

Thanks.


Cor Ligthert said:
Thomas,

Are you sure of that it is not reading however just throw an error because
you did not clear it in advance?

Just a thought?

Cor
 
Thomas,

I made a sample tried it and had not any problem at all.

static void Main()
{
Application.Run(new Form1());
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add("mycolumn",Type.GetType("System.DateTime"));
ds.Tables.Add(dt);
DateTime mydate;
mydate = DateTime.Now;
for (int i = 0; i <10 ;i++)
{
DataRow dr = dt.NewRow();
dr[0]= mydate.AddDays(i);
dt.Rows.Add(dr);
}
ds.WriteXml(@"C:\F1.xml");
ds = new DataSet();
dt = new DataTable();
dt.Columns.Add("mycolumn",Type.GetType("System.Int32"));
ds.Tables.Add(dt);
for (int i = 0; i <10 ;i++)
{
DataRow dr = dt.NewRow();
dr[0]= i.ToString();
dt.Rows.Add(dr);
}
ds.WriteXml(@"C:\F2.xml");
}
private void button3_Click(object sender, System.EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXml(this.textBox1.Text);
this.dataGrid1.DataSource = ds.Tables[0];
}
}
 
Thomas,

When I use this code without the ds.clear I have the same effect as you.

DataSet ds = new DataSet();
private void button3_Click(object sender, System.EventArgs e)
{
ds.Clear();
ds.ReadXml(this.textBox1.Text);
this.dataGrid1.DataSource = ds.Tables[0];
)

With the ds.Clear(); it shows when I change the textbox two different
datasets.

Instead of the ds.Clear() you can use of course as well
ds = new DataSet();

That was what I tried to show you.

I hope this helps?

Cor
 
hum.. really strange....

It doesn't work for me with the ds.Clear()....

I will search for another way to do what i want.

Thank you again :)

Bye.
 
Back
Top