Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

My goal is to read an .xml into a dataset using .net (C#), so I can dump it into a datagrid. However, I am having trouble reading the .xml file into my dataset. Any ideas what I am doing wrong?

 

This is what my test.xml file looks like:

[color=Blue]<book>
    <title>Book Title</title>
    <chapter>Chapter 1</chapter>
</book>[/color]

 

This is what my code behind looks like:

[color=Green]private void Page_Load(object sender, System.EventArgs e)
{

[indent]if (!IsPostBack)
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("test.xml"));
[color=Olive] // The table name is entitled "title" because
//that is the first element in the test.xml file[/color]
datagrid1.DataSource = ds.Tables["title"];
datagrid1.DataBind();	
}[/indent]

}[/color]

 

This is what my .aspx file looks like:

[color=Red]<asp:datagrid id="datagrid1" runat="server" AutoGenerateColumns="True">
<Columns><asp:BoundColumn DataField="title"></asp:BoundColumn></Columns>				
</asp:datagrid>[/color]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...