views:

80

answers:

1

Ok so I have made a DataSet that reads the data hardcoded but unsure how I can read input from user to replace that hardcoded data.

I have a form with a textbox and submit button, I want to save data to xml after going through my DataSet.

Kinda new to programming, hoping someone can give me some pointers here.

public partial class Form1 : Form
{   

    // DataSet

    DataSet ds = new DataSet();
    DataColumn email = new DataColumn();

    public Form1()
    {
        InitializeComponent();

        email = new DataColumn("Email", Type.GetType("System.String"));            
        ds.dt.Rows.Add(0, "my_email");
        ds.dt.Rows.Add(1, "my_email");

        var results = from myRow in ds.dt
                      orderby myRow.id
                      where myRow.id == 0
                      select myRow;

        foreach (var item in results)
        {
            ds.dt.WriteXml("email.xml");  
        } 
    }

}

A: 

Not really sure what you're trying to do without further information. Maybe this will get you a bit further?

public partial class Form1 : Form
{
    DataSet ds = new DataSet();

    public Form1()
    {
        InitializeComponent();

        ds.Tables.Add("dt");
        ds.Tables[0].Columns.Add("id");
        ds.Tables[0].Columns.Add("email");
    }

    private void button1_Click(object sender, EventArgs e)
    {
        int count = ds.Tables[0].Rows.Count;
        ds.Tables[0].Rows.Add(count, textBox1.Text);
    }

    private void button2_Click(object sender, EventArgs e)
    {
        ds.Tables[0].WriteXml("email.xml");
    }
}

One textbox for input, one button for adding items to the dataset from the inputbox and one button for writing the xml to a file.

Claus
That was exactly what I needed, thanks.
Zubirg