Using XmlDataSource in a Standalone Program

How does one successfully use an XmlDataSource in a stand-alone program to populate a DataGridView

All of the samples I see will work fine on a web page but it just doesn't work standalone. Am I missing something obvious Do I need another cup of coffee

TIA!

Ken

Here's my code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Web;
using System.Web.UI.WebControls;
//using System.Web.UI.WebControls;

namespace xml_data1
{
public partial class Form1 : Form
{
public XmlDataSource XMLDataSet;

private void Form1_Load(object sender, EventArgs e)
{
XMLDataSet = new XmlDataSource();

XMLDataSet.DataFile = (@"D:\work\myplay\xml_data1\xml_data1\XMLData.xml");

// the below DOES retrieve the data
XmlDocument dadata = XMLDataSet.GetXmlDocument();

XMLDataSet.DataBind();
//
//dgMain.DataSource = dadata; // nope
dgMain.DataSource = XMLDataSet;
//dgMain.DataMember = "Customer";
}
}
}




Answer this question

Using XmlDataSource in a Standalone Program

  • project_tek


    Hi Ken,

    The XMLDataSource is used for Web Form.It is under the System.Web.UI.WebControls Namespace.
    For Winform application, I think you may try to use the DataSet, which has a method ReadXML.
    Please note the XML file must be a two dimensions table or it will be broken into a few tables in the DataSet.

    If you still have any concern, please feel free to post here.

    Best regards,
    Peter Huang



  • davidvl

    Hi Ken,

    I am just checking to see how this is going.
    Please drop me a quick note at your convenience to let me know the current status of this issue.
    If you have any concerns, please do not hesitate to let me know.
    Thanks, and have a great day! :)

    Best regards,
    Peter Huang



  • Bordak

    Hi!

    If I remember right - DataBind() must be called after you set DataSource/DataMember.

    I don't understand about "standalone program" - did you mean Windows Forms Application Then you do not have web controls, but WinForms controls.


  • Using XmlDataSource in a Standalone Program