Click here to Skip to main content
15,897,315 members
Please Sign up or sign in to vote.
1.92/5 (4 votes)
See more:
Hello Team,

I have datagrid on WPF form and I would like to perform Insert, Update & Delete.
I have code which do the same for me in Windows Forms but Want to the same in WPF..
Please help...


C#
        OleDbConnection Con_Admin = new OleDbConnection();
        BindingSource bs = new BindingSource();
        OleDbDataAdapter da;
        DataTable dt; 

public void Show_Admin_GridView()
        {
            try
            {
                Con_Admin.Open();
            }
            catch { }


            dataGridView1.DataSource = null;

            da = new OleDbDataAdapter(frm2_HomePage.frm8_Admin_GridQry, Con_Admin);
            OleDbCommandBuilder MyCommandBuilder = null;
            MyCommandBuilder = new OleDbCommandBuilder(da);
            dt = new DataTable();
            da.Fill(dt);
            bs.DataSource = dt;
            dataGridView1.DataSource = bs;
            dataGridView1.Enabled = true;

            dataGridView1.AutoResizeColumns();

            try
            {
                Con_Admin.Close();
            }
            catch { }

        }

        public void SaveChanges()
        {
            try
            {
                da.Update(dt);
            }
            catch (Exception exceptionObj)
            {
                MessageBox.Show(exceptionObj.Message.ToString());
            }
            
        }
Posted
Comments
[no name] 21-Sep-13 9:07am    
"Want to the same in WPF" okay so go ahead and research WPF, MVVM and databinding.
Pravinkarne.31 21-Sep-13 9:14am    
In WinForm we can use BindingSource, Even if you help me with How we can use BindingSource(OR Similler thing) in WPF will solve my problm
[no name] 21-Sep-13 9:19am    
research WPF, MVVM and databinding

1 solution

 
Share this answer
 
Comments
Pravinkarne.31 23-Sep-13 5:35am    
But In WinForm we can use BindingSource, Do you know how we can use BindingSource(OR Similler thing) in WPF, So that the grid will updated automatically(with less code)
Pravinkarne.31 2-Oct-13 0:25am    
But In WinForm we can use BindingSource, Do you know how we can use BindingSource(OR Similler thing) in WPF, So that the grid will updated automatically(with less code)!!!

Please Help!!!
ridoy 2-Oct-13 13:21pm    
Ok,sorry for some late as i was away from my pc probably for what you downvoted me,:). Anyway,alternately i think you can use ItemsSource.See some examples here: http://stackoverflow.com/questions/5398441/how-to-set-the-datasource-of-a-datagrid-in-wpf/15792141#15792141, http://stackoverflow.com/questions/5809816/datagrid-binding-in-wpf, http://stackoverflow.com/questions/10138590/how-to-set-datagrids-bindingsource-via-xaml

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900