Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating a Datagrid Using ReadXML 1

Status
Not open for further replies.

barrylowe

Programmer
Nov 6, 2001
188
GB
I have set up a small test project to investigate the use of XML files in ASP.NET pages.

I have written code which quite happily creates an XML file based on the contents of a Dataset using the WriteXML method.

I am now trying to populate a datagrid based on the contents of an XML file using the ReadXML method, this is where I am having problems. Each time I run the page I get the following error triggered when I call the DataBind method:

"The IListSource does not contain any data sources"

I am assuming that this is because the dataset is empty. The code I am using to populate the dataset is:

Dim strFileName As String = "D:\Development\IS_DEV\ASP_NET\jobshop\XMLfiles\Datagrid.xml"
DataSet2.ReadXml(strFileName, XmlReadMode.IgnoreSchema)
DataGrid1.DataSource = DataSet2
DataGrid1.DataBind()

Can anyone help?
 
I am assuming that this is because the dataset is empty
Have you stepped through your code and confirmed if this is true?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I have stepped through the code and discovered that it fails on the DataBind command.

I am not sure of the best way to test that the dataset is populated. Any tips?
 
Are you using VS? If so, you can either:

1) hover over the DataSet and use the built in viewer
2) Use the command window and type "? DataSet2.Tables(0).Rows.Count"

If not, you could just print out what DataSet2.Tables(0).Rows.Count equals.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I used your 2nd technique and I got the following result:

Run-time exception thrown : System.IndexOutOfRangeException - Cannot find table 0.

Does this mean that the dataset is in fact empty?
 
Yes. It means it has no tables.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
So to get back to my original question, can anyone see what I am doing wrong in my code?
 
Have you:

1) Verified the path is correct
2) Verified that the file is correctly populated with data
3) Tried it without the XmlReadMode.IgnoreSchema parameter


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks for that, it appears to have been a problem with the XMLReadMode parameter.

I knew it wasn't either of the first 2 points. I will need to read up further on XMLReadMode.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top