.NETGURU
DataSet : Error when trying to use ReadXml the 2nd time
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.adonet.

Post a new message to this list...

LEBRUN Thomas
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.

--
LEBRUN Thomas
http://morpheus.developpez.com
Reply to this message...
 
    
Cor Ligthert
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

[Original message clipped]

Reply to this message...
 
    
LEBRUN Thomas
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" wrote:

[Original message clipped]

Reply to this message...
 
    
Cor Ligthert
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];
}
}

Reply to this message...
 
    
LEBRUN Thomas
Yes, i think you get no errors because you have define one dataset by
procedure/functions.

try this instead :
DataSet ds;

......

(in InitializeComponents, you have) :

this.ds = new DataSet();

And use :

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

The first time you click the button1, you have no problem.
The 2nd time, after you have changed the name of the file in textBox1.Text,
you will have the error i had.....

If you don't understand what i want to say, use this :

http://morpheus.developpez.com/temp/WindowsApplication6.zip

Thank.

"Cor Ligthert" wrote:

[Original message clipped]

Reply to this message...
 
    
Cor Ligthert
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

Reply to this message...
 
    
LEBRUN Thomas
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.

"Cor Ligthert" wrote:

[Original message clipped]

Reply to this message...
 
 
System.Data.DataRow
System.Data.DataSet
System.Data.DataTable
System.Data.XmlReadMode
System.DateTime
System.EventArgs
System.Int32
System.Type
System.Windows.Forms.Application




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification