Work in the disconnect environment

3 views
Skip to first unread message

anhtuan.songhong

unread,
Jul 23, 2014, 9:50:32 AM7/23/14
to ne...@googlegroups.com
Code Form1

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FarmADO
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            initData();
        }

        private static string FILENAME = "D:\\Farm.xml";
        FarmDS.FarmDataTable dtFarms = new FarmDS.FarmDataTable();

        public FarmDS.FarmDataTable DtFarms
        {
            get { return dtFarms; }
            set { dtFarms = value; }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            dtFarms.PrimaryKey = new DataColumn[] { dtFarms.Columns["Id"] };
            if (System.IO.File.Exists(FILENAME))
                dtFarms.ReadXml(FILENAME);
        }

        private void initData()
        {

        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            int id = int.Parse(txtId.Text);
            FarmDS.FarmRow row = (FarmDS.FarmRow)dtFarms.Rows.Find(id);
            if (row == null)
            {
                row = dtFarms.NewFarmRow();
                row.Id = id;
                row.Name = txtName.Text;
                row.Address = txtAddress.Text;
                row.Owner = txtOwner.Text;
                dtFarms.AddFarmRow(row);
                dtFarms.WriteXml(FILENAME);
            }
        }
    }
}

Reply all
Reply to author
Forward
0 new messages