views:

13

answers:

0

Hi,

I'm setting up a Dataset and DataTable in one section of my code. I'm having trouble understanding why update data in one area of my code why I don't see this in another area. I'm doing my best to use the same DataTable as far as I can tell (see code below).

What is the minimum I have to do if I want to see new rows that I add in one section of my code in a DataTable appear in the DataTable in another section of my code?

public partial class ManageLinksForm : Form
{
    List<ParentUrlDto> _parents = new List<ParentUrlDto>();
    MyDataSet myDataSet = MyDataSet.GetInstance();

    public ManageLinksForm()
    {
        InitializeComponent();
    }

    private void ManageLinksForm_Load(object sender, EventArgs e)
    {
        bindingSource2.DataSource = myDataSet.DT_Webfiles;
    }

    private void addParent_Button_Click(object sender, EventArgs e)
    {
        myDataSet.AddParent(newUrl_TextBox.Text);      
         // THIS IS WHERE I ADD A NEW ITEM
    }
}


public class MyDataSet
{
    public static MyDataSet myDataSet = null;
    private DataSet myData = new DataSet();
    public DataTable DT_Webfiles;

    public static MyDataSet GetInstance()
    {
        if (myDataSet == null)
        {
            return new MyDataSet();
        }
        else
        {
            return myDataSet;
        }
    }

    private MyDataSet()
    {
         // all setup & fill code
        this.DT_Webfiles = this.myData.Tables["WEBFILES"];
    }

    public void AddParent(string url)
    {
        DT_Webfiles.Rows.Add(<<new row code>>);
        DA_Webfiles.Update(this.myData, "WEBFILES");
    }

    public List<Uri> ParentUris()
    {
        var list = new List<Uri>();
        foreach (DataRow dr in DT_Webfiles.Rows)
        {
            var i = new Item(dr);
            if (i.isParent)
            {
                var uri = new Uri(i.Path);
                list.Add(uri);
            }
        }
        return list;
    }
}


public class Coordinator
{
    internal MyDataSet _myConfig;

    public Coordinator()
    {
        if (_myConfig == null)
        {
            _myConfig = MyDataSet.GetInstance();
        }
    }

     public void Process()
    {
        // -- RESET STATUS --
        _myConfig.ResetStatus();

        // --- EACH PARENT ---
        List<Uri> parentUris = _myConfig.ParentUris();     
        //THIS IS WHERE I DON'T SEE TO SEE THE NEW ITEMS, HOWEVER AFTER RESTARTING THE APP i DO
     }
}

THANKS