using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.Data;
using Telerik.WinControls.UI;

namespace OleDBConnection_App
{
    public partial class Form1 : Form
    {
        //public static OleDbConnection con3 = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source = " + Application.StartupPath + "\\parts.accdb");
        public static OleDbConnection con3 = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\temp\Nwind.mdb");
        public static DataTable dt = new DataTable();
        public OleDbDataAdapter adapter;
        public OleDbCommandBuilder commandbuider;
        public Form1()
        {
            InitializeComponent();
            this.Load += Form1_Load;
            //this.radGridView1.Rows.CollectionChanged += Rows_CollectionChanged;
            //OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\temp\Nwind.mdb");
            //conn.Open();
            //OleDbCommand cmd = new OleDbCommand("Select TOP 5 * FROM Customers", conn);
            //OleDbDataReader reader = cmd.ExecuteReader();
            //radGridView1.MasterTemplate.LoadFrom(reader);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //  string SQL = "SELECT * from supplier";
              string SQL = "Select TOP 5 * FROM Customers";
            adapter = new OleDbDataAdapter(SQL, con3);
            commandbuider = new OleDbCommandBuilder(adapter);

            adapter.Fill(dt);

            radGridView1.DataSource = dt;

            radGridView1.RowsChanged += new GridViewCollectionChangedEventHandler(PartsGrid_Update);
        }

        private void PartsGrid_Update(object sender, GridViewCollectionChangedEventArgs e)
        {
            if (adapter.Update(dt) > 0)
            {
                MessageBox.Show("done");
            }
        }
        private void Rows_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
           
        }
    }
}
