简体   繁体   中英

Display specific rows and update in GridView using Linq database c#

I am new in C# and I want to display specific rows in GridView. I could do this but I could not update it. My code:

 private void bindGridView()
    {
        myContextDataContext context = new myContextDataContext();
        var q2 = from p in context.employees
                 where p.check_is_mngr == 1
                 select p;
        employeeDataGridView.DataSource = q2;
    }

I called bindgridview() in bossAcc_Load function.In my form,I have add_new button and save button. This is save button function:

private void button5_Click(object sender, EventArgs e)
    {
        this.Validate();
        this.employeeBindingSource.EndEdit();
        this.tableAdapterManager.UpdateAll(this.my_proDataSet);   

    }

But when I click save button,didn't update data.What should I do?

Try this,

var q2 = from p in context.employees
                 where p.check_is_mngr == 1
                 select p;
employeeDataGridView.DataSource = null;
employeeDataGridView.DataSource = q2 ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM